Skip to main content

client.postcodes

Lookup Postcode

Returns the complete list of addresses for a postcode. Postcode searches are space and case insensitive.

Each request looks up one postcode. To extract the addresses for several postcodes, send one request per postcode.

Use it to power postcode driven address searches, like Postcode Lookup.

Postcode lookup covers the United Kingdom, the Republic of Ireland, the Netherlands and Singapore. The API detects the format of the postcode you submit. UK and Irish postcodes are searched by default. For a Dutch or Singapore postcode, set context to NLD or SGP, or to GLOBAL to accept any supported format.

UK postcodes need PAF, Multiple Residence, Not Yet Built, PAF Alias, PAF Welsh, AddressBase or AddressBase Premium on your key. Eircodes need ECAD or ECAF. Dutch postcodes need Kadaster. Singapore postcodes need HERE Asia Pacific. Without a matching licence the request is rejected.

An unfound postcode costs no lookup. A postcode that returns addresses costs one.

Postcode Not Found​

Invalid postcodes do not affect your lookup balance. The API returns a 404 response with this body:

{
"code": 4040,
"message": "Postcode not found",
"suggestions": ["SW1A 0AA"]
}

Suggestions​

If a postcode cannot be found, the API returns up to 5 of the closest matching postcodes. It corrects common errors first (e.g. mixing up O and 0 or I and 1).

If the suggestion list is small (fewer than 3), the correct postcode is likely to be among them. Notify the user or trigger new searches immediately.

The suggestion list is empty if the postcode has deviated too far from a valid postcode format.

Multiple Residence​

A small number of postcodes return more than 100 premises. The API returns 100 addresses per page, so use page to paginate the result set.

Endpoint​

GET /postcodes/{postcode}

See the API reference for this endpoint.

Signature​

def postcodes(
postcode,
filter: nil,
page: nil,
tags: nil,
remove_organisation: nil,
dataset: nil,
context: nil
)

Arguments​

NameTypeRequiredDescription
postcodeStringyesPostcode to retrieve
keywordskeyword argumentsnoOne per query parameter, named as the API names them. A keyword left out or nil is not sent.

Query Parameters​

Pass these as keyword arguments.

NameTypeRequiredDescription
filterString, Array<String>noRestrict Result Fields
pageIntegernoPage
tagsString, Array<String>noTags
remove_organisationStringnoRemove Organisation
datasetArray<String>noFilter by Dataset
contextStringnoContext

Response​

IdealPostcodes::Responses::PostcodeResponse. Read fields with readers named as the API names them, such as response.result, or with response["result"]. to_h returns the decoded body.

Errors​

An HTTP error raises IdealPostcodes::ApiError with the HTTP status, the API error code and the decoded body. A transport failure raises IdealPostcodes::TransportError. See error handling.

Example​

postcodes.rbruby
require "ideal_postcodes"

client = IdealPostcodes::Client.new(api_key: "ak_test")

response = client.postcodes("BR8 7RE")

response.result.each do |address|
puts "#{address.line_1}, #{address.post_town}, #{address.postcode}"
end