Page-based Pagination (REST)
The REST API uses page-based pagination. Each response includes the current page of items plus metadata telling you the total number of items, how many pages exist, and whether there are more pages to fetch.Examples below are in TypeScript. The patterns applies to any language with
an HTTP client.
Making a Paginated Request
Response Structure
Every paginated REST response follows this structure:Metadata Fields
Requesting a Specific Page
Pass pagination parameters in the query string:Fetching the Next Page
UsehasNextPage and nextPageNumber to decide whether more results exist:
Fetching All Pages
To retrieve every item across all pages, loop untilhasNextPage is false:
Cursor-based Pagination (GraphQL)
The GraphQL API uses cursor-based pagination. Instead of page numbers, you use an opaque cursor string to request the next set of results. This is more reliable for large, frequently changing datasets because new or deleted records don’t shift the page boundaries.Making a Paginated Request
Passfirst (page size) and optionally after (cursor) as query variables:
pageInfo object tells you whether more pages exist and provides the cursor for the next page.
Response Structure
Metadata Fields
Fetching the Next Page
Pass theendCursor from the previous response as the after variable on the next request, and stop when hasNextPage is false:
endCursor from each response as the after variable in the next request. Stops when hasNextPage is false.
Best Practices
Use the smallest page size you need. Use smaller page sizes for UI-driven fetching (10-20 items). Use larger sizes only for background sync or batch jobs (50-100 items). Don’t rely on total counts for logic. BothtotalItems (REST) and totalCount (GraphQL) can change between requests as data is created or deleted. Use them for display only, not for control flow.
Handle empty pages gracefully. If a page has no items (e.g., records were deleted between requests), the items array will be empty. Don’t treat this as an error:
Quick Reference
What’s Next?
Rate Limiting
Understand request quotas, especially important when fetching many
pages.
Error Handling
Handle errors that may occur during paginated fetches.
Using Platform APIs
Full guide to querying the GraphQL API with filtering, sorting, and
pagination.
Webhooks
Instead of polling pages for changes, use webhooks to get notified in
real time.