Paginated lists in our API: page, per_page and reading every page without wasting requests

WhatsApp & APIs·· 9 views· 3 min read

The short answer: list operations return their results in pages. You pick the page with page (the first is 1) and how many results you want with per_page, from 1 to 100; without it you get 10. The answer's meta gives the total and how many pages there are.

The parameters

Parameter What it is
page The page number. The first is 1.
per_page Results per page, from 1 to 100. Default 10.

curl "https://api.mozout.co.mz/v1/domains?page=2&per_page=50" -H "Authorization: Bearer $RLX_API_KEY"

What the answer contains

{
"data": [ ... ],
"meta": { "page": 2, "per_page": 50, "total": 120, "total_pages": 3 }
}

Field in meta What it is
page The page returned.
per_page Results per page.
total Results in total.
total_pages Pages in total.

Reading every page

1 Start at page=1, ideally with per_page=100.
2 Add the results in data to what you already have.
3 Carry on while page is lower than total_pages, asking for the next page.
4 Respect the limits: each page counts as one request. If you get a 429, wait for Retry-After and continue where you stopped.
A long list with a small per_page wastes requests. 120 domains at 10 per page take 12 requests; at 100 per page, 2. With 90 requests per minute per key, the difference shows. See the request limits.

Which lists are paginated, and their filters

List Order Filter
GET /v1/domains Next to expire first status, for example ?status=active
GET /v1/services Most recent first status, for example ?status=active
GET /v1/invoices Most recent first status, for example ?status=unpaid
GET /v1/tickets Most recent reply first status, for example ?status=open
GET /v1/servers
GET /v1/catalog/products group_id
GET /v1/extras kind, for example ?kind=ssl
GET /v1/account/contacts, GET /v1/account/users For users, the owner first
GET /v1/reseller/services
Filter before you paginate. If you only want unpaid invoices, ?status=unpaid&per_page=100 brings what matters in far fewer pages than reading every invoice and filtering afterwards. To find out whether something changed without reading it all again, see also webhook or polling.

Want to try pagination without writing code? The documentation, reached from the API page, has the Playground on every list operation.

See the API page

SEE ALSO

API request limits: per key, per account and per task, the headers and what to do after a 429

Our API's error codes: what each one means, and which ones are worth retrying

Domains through the API: checking a name, registering, renewing and transferring with credit

Invoices through the API: listing, PDF, paying with credit, renewal cycle and cancellations

Our API in one page: what you can automate in your account, area by area

Webhook or polling: how one system learns that something changed in another

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from 396,00 MT/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.