# `client.PostcodesAsync()`

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](https://docs.ideal-postcodes.co.uk/docs/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:

```json
{
  "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](/docs/api/postcodes.md) for this endpoint.

## Signature

```csharp
Task<PostcodeResponse> PostcodesAsync(string postcode, PostcodesParams? query = null, CancellationToken cancellationToken = default)
```

## Arguments

| Name                | Type                | Required | Description                                                           |
| ------------------- | ------------------- | -------- | --------------------------------------------------------------------- |
| `postcode`          | `string`            | yes      | Postcode to retrieve                                                  |
| `query`             | `PostcodesParams`   | 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            |
| --------------------- | ----------------------- | -------- | ---------------------- |
| `filter`              | `string`                | no       | Restrict Result Fields |
| `page`                | `int`                   | no       | Page                   |
| `tags`                | `string`                | no       | Tags                   |
| `remove_organisation` | `string`                | no       | Remove Organisation    |
| `dataset`             | `IReadOnlyList<string>` | no       | Filter by Dataset      |
| `context`             | `string`                | no       | Context                |

## Response

`PostcodeResponse`. 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

postcodes.cscsharp

```csharp
using IdealPostcodes;

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

var response = await client.PostcodesAsync("BR8 7RE");

foreach (var address in response.Result)
{
    Console.WriteLine($"{address.Line1}, {address.PostTown}, {address.Postcode}");
}
```
