# `client.FindAddressAsync()`

Find Address

Returns address suggestions for a partial address, ordered by relevance. Use it to power real-time address autofill.

Consider our address autocomplete JavaScript libraries, which add address lookup to a form without calling this API directly.

## API Usage

Implementing our Address Autocomplete API involves:

1. Fetch address suggestions with `/autocomplete/addresses`
2. Acquire the complete address using the ID from the suggestion

Step 2 decrements your lookup balance.

Step 1 is not a free standalone resource. We rate limit and then suspend integrations that repeatedly make autocomplete requests without a paid Step 2 request.

## Context

`context` limits the search, usually to a single country. It defaults to `GBR`, and an unrecognised context falls back to that default. If your key is not licensed for the datasets covering the context, the request is rejected.

Querying a full postcode within a supported context returns the entire address list for that postcode.

## Query Filters

Refine results by appending filters to your querystring, e.g. `postcode=sw1a2aa` for postcode `SW1A 2AA`. Invalid filters return an empty set without affecting your lookup count.

To apply multiple filter terms, use a comma-separated list, e.g. `postcode_outward=e1,e2,e3` combines result sets for E1, E2 and E3. Unless otherwise specified, all filters support multiple terms.

Filters combine with `AND` logic, for instance `su_organisation_indicator=Y&postcode_area=n`. The maximum is **8** filter terms.

## Address Bias

Preface bias searches with `bias_` to boost certain address results. Unlike filters, biasing allows unmatched addresses to appear with lower priority.

For example, use `bias_postcode_area=SW,SE` to favour addresses in the `SW` and `SE` postcode areas. Invalid bias terms have no effect.

Multiple bias terms are allowed unless stated otherwise, with a combined maximum of **5**.

## Suggestion Format

The suggestion format is subject to change. We recommend using the suggestion as-is to avoid integration issues.

## Rate Limiting and Cost

The default rate limit is 3,000 requests per 5 minutes, counted per key and IP address. The `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset` headers report where you stand.

Autocomplete API usage does not impact your balance, but resolving a suggestion to a full address requires a paid request. Autocomplete requests without subsequent paid requests may lead to rate limiting or suspension.

## Endpoint

`GET /autocomplete/addresses`

See the [API reference](/docs/api/find-address.md) for this endpoint.

## Signature

```csharp
Task<AutocompleteResponse> FindAddressAsync(FindAddressParams? query = null, CancellationToken cancellationToken = default)
```

## Arguments

| Name                | Type                | Required | Description                                                           |
| ------------------- | ------------------- | -------- | --------------------------------------------------------------------- |
| `query`             | `FindAddressParams` | no       | Query parameters. Fields under [Query Parameters](#query-parameters). |
| `cancellationToken` | `CancellationToken` | no       | Cancels the request.                                                  |

## Query Parameters

Set these on the `query` argument. Each property is the name in PascalCase, such as `PostTown` for `post_town`; required fields are constructor arguments.

| Name                        | Type                    | Required | Description                                                                                                                                                                   |
| --------------------------- | ----------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `query`                     | `string`                | no       | Address Query                                                                                                                                                                 |
| `dataset`                   | `IReadOnlyList<string>` | no       | Filter by Dataset                                                                                                                                                             |
| `context`                   | `string`                | no       | Context                                                                                                                                                                       |
| `limit`                     | `int`                   | no       | Limit                                                                                                                                                                         |
| `bias_lonlat`               | `string`                | no       | Bias by Geolocation                                                                                                                                                           |
| `bias_ip`                   | `string`                | no       | Bias by Geolocation of IP                                                                                                                                                     |
| `box`                       | `string`                | no       | Filter by Bounding Box                                                                                                                                                        |
| `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`                      | `long`                  | 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                                                                                                                                              |
| `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                                                                                                                                                               |
| `postal_code`               | `string`                | no       | Filter by postal code                                                                                                                                                         |
| `postal_code_2`             | `string`                | no       | Filter by postal code prefix                                                                                                                                                  |
| `postal_code_3`             | `string`                | no       | Filter by short postal code                                                                                                                                                   |
| `city`                      | `string`                | no       | Filter by city                                                                                                                                                                |
| `state`                     | `string`                | no       | Filter by state                                                                                                                                                               |
| `state_code`                | `string`                | no       | Filter by state code                                                                                                                                                          |
| `bias_postal_code`          | `string`                | no       | Bias by postal code                                                                                                                                                           |
| `bias_postal_code_2`        | `string`                | no       | Bias by postal code prefix                                                                                                                                                    |
| `bias_postal_code_3`        | `string`                | no       | Bias by short postal code                                                                                                                                                     |
| `bias_city`                 | `string`                | no       | Bias by city                                                                                                                                                                  |
| `bias_state`                | `string`                | no       | Bias by state                                                                                                                                                                 |
| `bias_state_code`           | `string`                | no       | Bias by state code                                                                                                                                                            |
| `is_pobox`                  | `string`                | no       | Filter by PO Box                                                                                                                                                              |
| `is_business`               | `string`                | no       | Filter by business address                                                                                                                                                    |

## Response

`AutocompleteResponse`. Fields are properties in PascalCase, such as `response.Result`; fields this SDK version does not know are kept in `AdditionalProperties`. See [responses](/docs/sdks/dotnet/responses.md).

## Errors

An HTTP error throws `ApiException` with the `StatusCode`, the API error `Code` and the raw `Body`. A success response whose body cannot be read throws `UnserializableResponseException`. Network failures and cancellation throw `HttpClient`'s own `HttpRequestException` and `OperationCanceledException`. See [error handling](/docs/sdks/dotnet/errors.md).

## Example

find-address.cscsharp

```csharp
using IdealPostcodes;

using var client = new IdealPostcodesClient("ak_test");

var response = await client.FindAddressAsync(new FindAddressParams { Query = "9 Malyons Road", Limit = 5 });

foreach (var hit in response.Result.Hits)
{
    Console.WriteLine($"{hit.Id}: {hit.Suggestion}");
}
```
