Pagination
Pagination for the Limitry API
Several endpoints support pagination to retrieve large datasets efficiently.
Cursor-Based Pagination
The API uses cursor-based pagination for endpoints that return lists of items. This provides consistent results even when new items are added during pagination.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
limit | integer | No | Number of items per page (default: 50, max: 100) |
cursor | string | No | Pagination cursor from previous response |
Response Format
Paginated responses include a cursor field in the response:
{
"data": [
// ... array of items
],
"cursor": "eyJpZCI6ImV2dF8xMjM0NTY3OCIsInRpbWVzdGFtcCI6IjIwMjQtMDEtMTVUMTA6MzA6MDBaIn0",
"hasMore": true
}Pagination Flow
-
First Request: Omit the
cursorparameter to get the first pageGET /v1/events?limit=50 -
Next Page: Use the
cursorfrom the previous responseGET /v1/events?limit=50&cursor=eyJpZCI6ImV2dF8xMjM0NTY3OCIsInRpbWVzdGFtcCI6IjIwMjQtMDEtMTVUMTA6MzA6MDBaIn0 -
Check for More: Use the
hasMorefield to determine if there are more pageshasMore: true- More items available, use thecursorto fetch the next pagehasMore: false- No more items, you've reached the end
Example
let cursor: string | undefined
let allEvents = []
do {
const response = await limitry.events.list({
limit: 50,
cursor,
})
allEvents.push(...response.data)
cursor = response.cursor
} while (response.hasMore)Best Practices
- Use appropriate
limitvalues: Balance between number of requests and response size - Handle empty responses: The
dataarray may be empty even ifhasMoreis true - Don't modify cursors: Cursors are opaque strings - don't try to parse or modify them
- Respect rate limits: Large pagination operations may hit rate limits