Skip to main content

client.AddressCleanse()

Cleanse Address

Returns the closest matching address for a freeform address input, with Match Level indicators describing how closely each element of the suggested address matches the input. The more impaired the input address, the harder it is to cleanse.

A cleanse that returns a match costs a lookup. A no-match response is free.

Countries​

Cleanse defaults to the UK. Pass context with an ISO 3166-1 alpha-3 country code to cleanse an address elsewhere, e.g. context=USA or context=FRA. The address datasets your key is licensed for decide which countries it can cleanse.

The response shape is the same for every country: a standardised address in match, the raw source record in match.native and the same confidence, fit and Match Level indicators. The Match Levels and confidence score are at their most discriminating for the UK, where cleanse runs against purpose-built indexes; elsewhere they are computed from the country's address dataset.

Confidence Score​

Each incorrect, missing or misspelled element subtracts from the overall confidence score.

Deciding on an Acceptable Confidence Score Threshold​

Inputs differ widely between address cleanse projects. Within a project, though, they tend to repeat the same errors. Some datasets are keyed in by hand and prone to typos. Others have a persistently missing datapoint such as organisation name or postcode. There is no absolute Confidence Score threshold. Set the acceptable score project by project, based on the systematic errors in the data and your business goals.

To set a threshold, load a subset of the dataset into a spreadsheet application like Excel and sort on the score. Scrolling from top to bottom shows matches from best to worst. As you reach the lower quality searches you can judge roughly:

  • Which confidence scores indicate ambiguous matches (i.e. up to building level only)
  • Which confidence scores indicate a poor or no match (i.e. the nearest matching address is too far from the input address)

Depending on your business goals, you can also use the Match Levels to determine an acceptable match. You may need to match only up to the thoroughfare or building name, or accurate organisation names may matter.

Endpoint​

POST /cleanse/addresses

See the API reference for this endpoint.

Signature​

func (c *Client) AddressCleanse(ctx context.Context, body AddressCleanseBody, params *AddressCleanseParams) (*CleanseResponse, error)

Arguments​

NameTypeRequiredDescription
ctxcontext.ContextyesCancels the request and sets its deadline.
bodyAddressCleanseBodyyesThe JSON request body. Fields under Request Body.
params*AddressCleanseParamsnoOptional 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
tagsstringnoTags
remove_organisationstringnoRemove Organisation
contextstringnoIdentify the country of the address to cleanse. Defaults to UK (GBR)

Request Body​

Set these as fields of body, named in Studly case (post_town is PostTown). An optional field is a pointer, set with new(value), or a map; nil sends nothing.

NameTypeRequiredDescription
querystringyesFreeform address input to cleanse
postcodestringnoOptionally specify the postal code for the address.
post_townstringnoOptionally specify the city or town of the address.
countystringnoOptionally specify the county of the address.

Response​

*idealpostcodes.CleanseResponse. 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​

address-cleanse/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.AddressCleanse(context.Background(), idealpostcodes.AddressCleanseBody{
Query: "9 Malyons Rd, Swanley, BR8",
Postcode: new("BR8 7RE"),
}, nil)
if err != nil {
log.Fatal(err)
}
switch result := res.Result.Variant().(type) {
case *idealpostcodes.GbrCleanseMatch:
fmt.Printf("%s, %s\n", result.Match.Line1, result.Match.Postcode)
fmt.Println("Confidence:", result.Confidence)
case *idealpostcodes.GbrCleanseNoMatch:
fmt.Println("No match for", result.Query)
}
}