$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
public function addressCleanse(array $body, array $params = []): CleanseResponse
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
$body | array | yes | The JSON request body. Keys under Request Body. |
$params | array | no | Query parameters. Keys under Query Parameters. |
Query Parameters
Pass these as keys of $params.
| Name | Type | Required | Description |
|---|---|---|---|
tags | string|list<string> | no | Tags |
remove_organisation | 'true' | no | Remove Organisation |
context | string | no | Identify the country of the address to cleanse. Defaults to UK (GBR) |
Request Body
Pass these as keys of $body.
| Name | Type | Required | Description |
|---|---|---|---|
query | string | yes | Freeform address input to cleanse |
postcode | string | no | Optionally specify the postal code for the address. |
post_town | string | no | Optionally specify the city or town of the address. |
county | string | no | Optionally specify the county of the address. |
Response
IdealPostcodes\Responses\CleanseResponse. Read fields as properties, such as $response->result, or as an array with the API's field names. toArray() returns the decoded body.
Errors
An HTTP error throws ApiException with the HTTP status, the API error code from getCode() and the decoded body. A transport failure throws TransporterException. See error handling.
Example
<?php
declare(strict_types=1);
use IdealPostcodes\IdealPostcodes;
use IdealPostcodes\Types\GbrCleanseMatch;
require 'vendor/autoload.php';
$client = IdealPostcodes::client('ak_test');
$response = $client->addressCleanse([
'query' => '9 Malyons Rd, Swanley, BR8',
'postcode' => 'BR8 7RE',
]);
$result = $response->result;
if ($result instanceof GbrCleanseMatch) {
echo $result->match->line1, ', ', $result->match->postcode, PHP_EOL;
echo 'Confidence: ', $result->confidence, PHP_EOL;
echo 'Postcode match: ', $result->postcodeMatch, PHP_EOL;
} else {
echo 'No match for ', $result->query, PHP_EOL;
}