# Pagination, sorting and filtering

Every list answers a plain JSON array. The paging lives in the headers, so the body is the rows and nothing else.

## Pages

| Parameter | Meaning |
|---|---|
| `page` | 1-based page number, default 1 |
| `per_page` | rows per page, 1 to 100, default 50 (`limit` is an older name, read when `per_page` is absent) |

```http
GET /v1/orders?page=2&per_page=100
```

| Header | Meaning |
|---|---|
| `X-Total-Count` | rows matching the filters across all pages |
| `Link` | RFC 8288 links: `rel="first"`, `rel="prev"`, `rel="next"`, `rel="last"`, built from your own query |
| `X-Total-Capped` | `true` on the few very large lists whose count stops at 10,000 (show "10,000+"); `rel="last"` is then omitted and `rel="next"` keeps working |

Follow `rel="next"` until it is absent. The SDKs expose an async iterator that does this for you and surface `X-Total-Count`.

## Sorting

`sort` takes up to three comma-separated keys, each prefixed with `-` for descending:

```http
GET /v1/orders?sort=-captured_at,total_cents
```

Each list accepts a fixed set of keys, listed in its reference entry ("Sort keys: …") with its default. Any other key is `422 invalid_sort` (the error carries `allowed`); more than three is `422 too_many_sorts`. Rows without a value sort last; the row id breaks ties, so pages never overlap.

## Filters

- Enumerated fields filter as repeated array parameters: `status[]=paid&status[]=fulfilled`.
- Exact matches on your own references: `customer_ref=cus_A1B2`, `reference=INV-1001`.
- `q` is a contains search over the fields the reference names for that list.

## Dates and your time zone

| Parameter | Meaning |
|---|---|
| `from`, `to` | first and last day, `YYYY-MM-DD`, inclusive; an ISO-8601 date-time is taken as an exact instant |
| `range` | a rolling preset (`today`, `yesterday`, `last_7_days`, `last_30_days`, `this_month`, `last_month`, …); wins over `from`/`to` |
| `X-Timezone` header | the IANA zone the days are read in (`America/New_York`); absent: your merchant time zone, else UTC |

Each list filters one column, named in its reference entry ("The `from`, `to` and `range` filters read `created_at`").

```http
GET /v1/orders?range=last_7_days&status[]=paid
X-Timezone: America/Los_Angeles
```

## Exports

`GET /v1/reports/balance-transactions/export` answers CSV with the same filters and sort as the list plus `columns[]`; money stays integer cents. Past 10,000 rows it answers `422 export_too_large`: narrow the range.

## Timestamps

Every timestamp is UTC ISO-8601 with milliseconds and a `Z`: `2026-10-21T14:05:00.000Z`. Dates (payout days, period days) are `YYYY-MM-DD`.
