# `$client->addresses()`

Extract Addresses

Returns a list of UK addresses matching the query, ordered by relevance score. `limit` defaults to 10 and caps at 100. `page` defaults to 0.

You may only extract a single address from each request. To extract multiple addresses, you must perform an individual request for each address.

If the query is a valid postcode, the API returns the whole address list for that postcode and raises the limit to 100. Use `page` to reach the rest of a postcode holding more than 100 premises. You cannot page beyond 10,000 results.

Your key needs at least one of PAF, Multiple Residence, Not Yet Built, PAF Alias, PAF Welsh, AddressBase or AddressBase Premium. Without one the request is rejected.

A request that returns at least one address costs a lookup. Empty result sets are free.

## Reverse Geocoding

Return the addresses around a point with the `lon=` and `lat=` querystring arguments. The search radius is 100m and the API sorts addresses by distance from the point.

## Filters

Narrow your results by adding filters to your query string that correspond with an address attribute.

For instance, you can restrict to postcode `SW1A 2AA` by appending `postcode=sw1a2aa`.

If a filter term is invalid, e.g. `postcode=SW1A2AAA`, the API returns an empty result set and charges no lookup.

You can also scope using multiple terms for the same filter with a comma separated list of terms. E.g. Restrict results to E1, E2 and E3 outward codes: `postcode_outward=e1,e2,e3`. Multiple terms are `OR`'ed, i.e. the matching result sets are combined.

All filters can accept multiple terms unless stated otherwise below.

Multiple filters can also be combined. E.g. Restrict results to small user organisations in the N postcode area: `su_organisation_indicator=Y&postcode_area=n`. Multiple filters are `AND`'ed, i.e. each additional filter narrows the result set.

A combined maximum of 8 terms is allowed across all filters.

## Biases

You can boost address results that correspond with a given address attribute. All bias searches are prefixed with `bias_`.

Biased searches, unlike filtered searches, still allow unmatched addresses to appear. They rank lower.

For instance, you can boost addresses with postcode areas `SW` and `SE` by appending `bias_postcode_area=SW,SE`.

If a bias term is invalid, e.g. `bias_postcode=SW1A2AAA`, no bias is applied.

You may scope using multiple terms for the same bias with a comma separated list of terms. E.g. Prefer results in the `E1`, `E2` and `E3` outward codes: `bias_postcode_outward=e1,e2,e3`.

All biases can accept multiple terms unless stated otherwise below.

A combined maximum of 5 terms is allowed across all biases.

## Search by Postcode and Building Name or Number

Search by postcode and building attribute with the postcode filter and query argument. E.g. For "SW1A 2AA Prime Minister" `/v1/addresses?postcode=sw1a2aa&q=prime minister`.

Using a filter means a postcode mismatch returns no results and costs no lookup.

### Search by UPRN

Search by UPRN using the `uprn` filter and excluding the query argument. E.g. `/v1/addresses?uprn=100`.

## Endpoint

`GET /addresses`

## Signature

```php
public function addresses(array $params = []): AddressResponse
```

## Arguments

| Name      | Type    | Required | Description                                                         |
| --------- | ------- | -------- | ------------------------------------------------------------------- |
| `$params` | `array` | no       | Query parameters. Keys under [Query Parameters](#query-parameters). |

## Query Parameters

Pass these as keys of `$params`.

| Name                        | Type                   | Required | Description                                                                                                                                                                   |
| --------------------------- | ---------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `query`                     | `string`               | no       | Specifies the address to query.                                                                                                                                               |
| `limit`                     | `int`                  | no       | Limit                                                                                                                                                                         |
| `page`                      | `int`                  | no       | Page                                                                                                                                                                          |
| `filter`                    | `string\|list<string>` | no       | Restrict Result Fields                                                                                                                                                        |
| `lon`                       | `float\|int`           | no       | Longitude                                                                                                                                                                     |
| `lat`                       | `float\|int`           | no       | Latitude                                                                                                                                                                      |
| `postcode_outward`          | `string`               | no       | Filter by Outward Code                                                                                                                                                        |
| `postcode`                  | `string`               | no       | Filter by postcode Restrict result set to matching postcodes only. Can be combined with query to perform a postcode and building number or name search.                       |
| `postcode_area`             | `string`               | no       | Filter by Postcode Area                                                                                                                                                       |
| `postcode_sector`           | `string`               | no       | Filter by Postcode Sector                                                                                                                                                     |
| `post_town`                 | `string`               | no       | Filter by Town or City                                                                                                                                                        |
| `uprn`                      | `int`                  | no       | Filter by UPRN                                                                                                                                                                |
| `country`                   | `string`               | no       | Filter by country                                                                                                                                                             |
| `postcode_type`             | `string`               | no       | Filter by Postcode Type                                                                                                                                                       |
| `su_organisation_indicator` | `string`               | no       | Filter by Organisation Indicator                                                                                                                                              |
| `box`                       | `string\|list<string>` | no       | Filter by Bounding Box                                                                                                                                                        |
| `bias_postcode_outward`     | `string`               | no       | Bias by Outward Code Boosts addresses with a matching outward code. The outward code is the first half of a postcode. For instance, the outward code of `SW1A 2AA` is `SW1A`. |
| `bias_postcode`             | `string`               | no       | Bias by postcode Boost addresses which match postcode. Can be combined with query to perform a postcode and building number or name search.                                   |
| `bias_postcode_area`        | `string`               | no       | Bias by Postcode Area                                                                                                                                                         |
| `bias_postcode_sector`      | `string`               | no       | Bias by Postcode Sector                                                                                                                                                       |
| `bias_post_town`            | `string`               | no       | Bias by Town or City                                                                                                                                                          |
| `bias_thoroughfare`         | `string`               | no       | Bias by Street                                                                                                                                                                |
| `bias_country`              | `string`               | no       | Bias by Country                                                                                                                                                               |
| `bias_lonlat`               | `string`               | no       | Bias by Geolocation                                                                                                                                                           |
| `tags`                      | `string\|list<string>` | no       | Tags                                                                                                                                                                          |
| `remove_organisation`       | `'true'`               | no       | Remove Organisation                                                                                                                                                           |
| `dataset`                   | `string\|list<string>` | no       | Filter by Dataset                                                                                                                                                             |

## Response

`IdealPostcodes\Responses\AddressResponse`. 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](/docs/sdks/php/errors.md).

## Example

addresses.phpphp

```php
<?php

declare(strict_types=1);

use IdealPostcodes\IdealPostcodes;

require 'vendor/autoload.php';

$client = IdealPostcodes::client('ak_test');

$response = $client->addresses(['query' => '9 Malyons Road, Swanley', 'limit' => 5]);

foreach ($response->result->hits as $address) {
    echo $address->line1, ', ', $address->postTown, ', ', $address->postcode, PHP_EOL;
}

echo $response->result->total, ' addresses matched', PHP_EOL;
```
