Developers
Page through API lists
How list endpoints return records a page at a time, and how to follow the Link header to read every page.
Reviewed
On this page
List endpoints, such as products, orders and customers, return records a page at a time. Each page links to the next one with a cursor, so the pages stay in order even while new records arrive.
Parameters
| Parameter | What it does |
|---|---|
limit |
How many records to return. The default is 50 and the most is 250. A larger number is cut to 250. A missing or zero value gives 50. |
page_info |
The cursor for the page you want. Take it from a Link header. Leave it out for the first page. |
Records come back in the order they were created, oldest first.
Follow the Link header
A list response carries a Link header with the addresses of the pages next to it:
Link: <https://<crate-address>/api/v1/products?limit=50&page_info=eyJ...>; rel="next",
<https://<crate-address>/api/v1/products?limit=50&page_info=eyJ...>; rel="previous"-
rel="next"appears only when more records follow. -
rel="previous"appears on every page after the first. - A response with no
Linkheader is the only page.
Use each address as it is. It keeps your other filters, so the next page uses the same filter.
Read every record
This loop reads every order and stops when there is no rel="next" link:
url="https://<crate-address>/api/v1/orders?limit=250"
while [ -n "$url" ]; do
curl -s -D headers.txt "$url" -H "Authorization: Bearer $CRATE_API_KEY" >> orders.jsonl
url=$(grep -i '^link:' headers.txt | grep -o '<[^>]*>; rel="next"' | sed 's/^<\(.*\)>;.*/\1/')
doneDo the same in your own code: follow the next link until it is gone. Don't count pages in advance.
Tips
- Use
limit=250for exports. It needs a fifth of the requests, which helps you stay under the rate limit. - If you copy records into your own database, store each
id. Update the record when it appears again, because records can change between pages. - To react to changes as they happen, use webhooks instead of reading the whole list on a timer.
Troubleshooting
Next steps
Was this helpful?
Still need a hand?
Tell us the task you were trying to complete and the message you saw. Include your store name or order reference when relevant. Keep passwords, API secrets and card details private.
Contact Crate