# idpc postcode

List every address at a postcode with `GET /postcodes/{postcode}`. A postcode that returns addresses costs one lookup; an unknown postcode costs nothing.

## `idpc postcode <postcode>`

| Flag               | Description                                                                                      |
| ------------------ | ------------------------------------------------------------------------------------------------ |
| `--page <n>`       | Page of results, 0-indexed (default `0`). Each page holds up to 100 addresses                    |
| `--country <iso3>` | `NLD` or `SGP` for a Dutch or Singapore postcode. UK and Irish postcodes are searched by default |

Postcodes are space and case insensitive.

**TTY (human):** prints one line per address, then the count and total.

**Non-TTY (agent):** emits JSON. `count` is the addresses on this page and `total` the addresses at the postcode across all pages:

```json
{
  "postcode": "BR8 7RE",
  "page": 0,
  "count": 41,
  "addresses": [
    {
      "id": "paf_2670849",
      "dataset": "paf",
      "line_1": "9 Malyons Road",
      "line_2": "Hextable",
      "line_3": "",
      "post_town": "Swanley",
      "postcode": "BR8 7RE",
      "udprn": 2670849,
      "uprn": "50002012147",
      ...
    },
    ...
  ],
  "suggestions": [],
  "total": 41
}
```

`...` marks fields and addresses left out of the example. Each address carries the full set of fields described in the [postcode lookup API reference](https://docs.ideal-postcodes.co.uk/docs/api/postcodes).

## Unknown postcodes

An unknown postcode is not an error. The command exits `0` with no addresses and up to five of the closest postcodes in `suggestions`:

```json
{
  "postcode": "BR87OE",
  "page": 0,
  "count": 0,
  "addresses": [],
  "suggestions": ["BR8 7DE", "BR8 7HE", "BR8 7BE", "BR8 7EE", "BR8 7AE"],
  "total": 0
}
```

## Agent pattern

```bash
# Every address at a postcode, one per line
idpc postcode "BR8 7RE" | jq -r '.addresses[] | [.line_1, .post_town, .postcode] | join(", ")'

# Fetch the second page of a large postcode
idpc postcode "CV4 7AL" --page 1
```
