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​

func (c *Client) Postcodes(ctx context.Context, postcode string, params *PostcodesParams) (*PostcodeResponse, error)

Arguments​

NameTypeRequiredDescription
ctxcontext.ContextyesCancels the request and sets its deadline.
postcodestringyesPostcode to retrieve
params*PostcodesParamsnoOptional query parameters, or nil. Fields under Query Parameters.

Query Parameters​

A required parameter is a method argument. Set the rest as fields of params, named in Studly case (post_town is PostTown); a field left at its zero value is not sent.

NameTypeRequiredDescription
filterstringnoRestrict Result Fields
pageintnoPage
tagsstringnoTags
remove_organisationstringnoRemove Organisation
dataset[]stringnoFilter by Dataset
contextstringnoContext

Response​

*idealpostcodes.PostcodeResponse. Fields the API may leave out or send as null are pointers. RawJSON() returns the body as received. See responses.

Errors​

An HTTP error returns *idealpostcodes.APIError with the HTTP status, the API error code and the body; match it with errors.AsType. A transport failure returns the net/http error, wrapped. See error handling.

Example​

postcodes/main.gogo
package main

import (
"context"
"fmt"
"log"

idealpostcodes "go.ideal-postcodes.co.uk/sdk"
)

func main() {
client := idealpostcodes.NewClient("ak_test")
res, err := client.Postcodes(context.Background(), "BR8 7RE", nil)
if err != nil {
log.Fatal(err)
}
for _, address := range res.Result {
fmt.Printf("%s, %s, %s\n", address.Line1, address.PostTown, address.Postcode)
}
}