# Website API

These routes belong to this website. They are not an AES Mail*SERVE SDK or the public USPS endpoint.

## Status

`GET /api/status`

```json
{"liveConfigured":false,"environment":"production","provider":"USPS Addresses API","maxBatchRows":25}
```

Configuration status only checks for the presence of credentials. It does not run an authorization request.

## One address

`POST /api/validate`, `Content-Type: application/json`

```json
{
  "mode": "sample",
  "address": {
    "streetAddress": "3120 M St NW",
    "secondaryAddress": "",
    "urbanization": "",
    "city": "Washington",
    "state": "DC",
    "ZIPCode": "20027"
  }
}
```

Use `mode: "live"` only for authorized provider checks. Required: streetAddress, city, state. ZIPCode is optional and accepts 5 digits or ZIP+4. urbanization is accepted for PR. US states, DC, listed territories and military state codes are accepted syntactically; provider support still determines the result.

Results contain `mode`, `provider`, `status`, `input`, `address`, `additionalInfo`, `notes`, plus corrections/matches when supplied. `address: null` means no address was returned. Live status values: `confirmed`, `needs_review`, `not_confirmed`, `standardized`, `not_matched`; batch failures may use `error`. Sample values are `sample` or `sample_not_found` and are never a live verification. Missing DPV is not treated as confirmed.

Live checks call OAuth client_credentials at `/oauth2/v3/token`, then `/addresses/v3/address` on the fixed production or TEM USPS host. The client secret is never returned to the browser. No custom upstream URL is accepted from a visitor.

## Batch

`POST /api/batch`

```json
{"mode":"sample","addresses":[{"streetAddress":"3120 M St NW","city":"Washington","state":"DC","ZIPCode":"20027"}]}
```

Accepts 1–25 rows, JSON body up to 64 KB. CSV import itself runs in the browser with a 100 KB limit. The API returns `{ "mode": "sample", "results": [...] }` in input order. A malformed input invalidates the batch before provider calls. Live errors appear per row when batch processing has begun. The Node adapter makes up to three concurrent calls; PHP processes sequentially.

## Error handling

- 400: invalid fields / JSON / unsupported mode
- 403: cross-origin browser request
- 404: unknown API route
- 405: unsupported method
- 413: body too large
- 415: unsupported request content type
- 429: application/provider rate limit (Node); PHP provider failures use 502
- 502/504: upstream failure / timeout (Node); PHP upstream timeout uses 502
- 503: live configuration missing, or unavailable PHP rate-limit storage

These endpoints support same-origin browser requests. They are not protected by customer accounts or API keys and are not designed as an unrestricted paid public API. Deploy edge access controls and usage limits appropriate to your USPS agreement before enabling credentials for broad public traffic.
