$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
public function postcodes(string $postcode, array $params = []): PostcodeResponse
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
$postcode | string | yes | Postcode to retrieve |
$params | array | no | Query parameters. Keys under Query Parameters. |
Query Parameters
Pass these as keys of $params.
| Name | Type | Required | Description |
|---|---|---|---|
filter | string|list<string> | no | Restrict Result Fields |
page | int | no | Page |
tags | string|list<string> | no | Tags |
remove_organisation | 'true' | no | Remove Organisation |
dataset | string|list<string> | no | Filter by Dataset |
context | string | no | Context |
Response
IdealPostcodes\Responses\PostcodeResponse. 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;
require 'vendor/autoload.php';
$client = IdealPostcodes::client('ak_test');
$response = $client->postcodes('BR8 7RE');
foreach ($response->result as $address) {
echo $address->line1, ', ', $address->postTown, ', ', $address->postcode, PHP_EOL;
}