Ideal Postcodes PHP SDK
ideal-postcodes/sdk calls the Ideal Postcodes UK address API from PHP 8.2 or later, with a typed method for each operation over any PSR-18 HTTP client.
Use the ak_test key for limited testing. It is capped at 5 requests per day. A new account comes with a free test balance for fuller testing.
composer require ideal-postcodes/sdk
use IdealPostcodes\IdealPostcodes;
$client = IdealPostcodes::client('ak_test');
$response = $client->findAddress(['query' => '9 Malyons Road']);
foreach ($response->result->hits as $hit) {
echo $hit->suggestion, PHP_EOL;
}
Each API operation is one method on the client, named from its operation ID, such as postcodes() or findAddress(). Every method returns a read-only object built from the API response.
Where does the address data come from?
UK addresses come from Royal Mail's Postcode Address File (PAF) and Ordnance Survey AddressBase, depending on the datasets on your key. Each address carries a dataset field naming its source, such as paf or abp. Its native record holds the raw fields from that source.
Why use the SDK?
- Any HTTP client. The SDK sends requests through the PSR-18 client already in your project, found by
php-http/discovery. Guzzle and Symfony HttpClient both work. There is no bundled transport to configure. - Generated from the OpenAPI spec. Every response is a typed, read-only object. Every dataset's native record has its own class, from
PafAddresstoUspsAddress. - Every current API operation. Address search, postcode lookup, UPRN lookup, autocomplete, address cleanse, places, email and phone validation, plus key, licensee and configuration management. Each one has its own reference page.
- Static analysis friendly. Parameters are PHPStan array shapes, enums are literal types and the source passes PHPStan at its strictest level.
What can coding agents use?
- Agent skill.
npx skills add ideal-postcodes/skillsinstalls theideal-postcodes-php-sdkskill, built from these pages. - Endpoints. Every operation, grouped by API area, with its parameters, response class and a tested example.
- Markdown pages. Add
.mdto any page URL for plain markdown, such as/docs/sdks/php/errors.md. - llms.txt. An index of every page on this site.
- OpenAPI spec. The API contract the SDK is generated from.
- Build with AI. Every asset for AI agents.
How do I authenticate?
Pass your API key to IdealPostcodes::client(). Key, licensee and configuration operations also need a Management Key, passed as the second argument. Keep the Management Key on your server. See setup.
How are errors reported?
An HTTP error throws ApiException with the HTTP status and the API error code and message. A failed connection throws TransporterException. Both implement IdealPostcodesException, so one catch covers the SDK. See error handling.