Pagination
In this guide, we will look at how to work with paginated responses when querying the Support Station API. By default, all list responses return 20 items per page. You can request up to 100 items per page by using the limit parameter.
Pagination Response Format
When an API response returns a list of objects, the response includes pagination metadata in the meta object:
- Name
meta.pagination.page- Type
- integer
- Description
The current page number (1-indexed).
- Name
meta.pagination.limit- Type
- integer
- Description
The number of items per page.
- Name
meta.pagination.total- Type
- integer
- Description
The total number of items across all pages.
- Name
meta.pagination.total_pages- Type
- integer
- Description
The total number of pages available.
Paginated response
{
"data": [
{ "id": "ticket-1", ... },
{ "id": "ticket-2", ... }
],
"meta": {
"pagination": {
"page": 1,
"limit": 20,
"total": 150,
"total_pages": 8
}
}
}
Query Parameters
Use these query parameters to control pagination:
- Name
page- Type
- integer
- Description
The page number to retrieve (default: 1).
- Name
limit- Type
- integer
- Description
The number of items per page, max 100 (default: 20).
Example: Paginating Tickets
In this example, we request the second page of tickets with 50 items per page.
Request
curl -G https://api.supportstation.io/api/v1/tickets \
-H "Authorization: Bearer {token}" \
-d page=2 \
-d limit=50
Response
{
"data": [
{
"id": "ticket-51",
"ticket_number": 51,
"subject": "Cannot access dashboard",
...
},
{
"id": "ticket-52",
"ticket_number": 52,
"subject": "Billing question",
...
}
],
"meta": {
"pagination": {
"page": 2,
"limit": 50,
"total": 150,
"total_pages": 3
}
}
}
Iterating Through All Pages
Here's an example of how to iterate through all pages of results:
Fetching all pages
async function getAllTickets() {
const tickets = [];
let page = 1;
let hasMore = true;
while (hasMore) {
const response = await fetch(
`https://api.supportstation.io/api/v1/tickets?page=${page}&limit=100`,
{
headers: {
'Authorization': `Bearer ${apiKey}`,
},
}
);
const data = await response.json();
tickets.push(...data.data);
const { pagination } = data.meta;
hasMore = page < pagination.total_pages;
page++;
}
return tickets;
}
Be mindful of rate limits when fetching large datasets. The API allows 100 requests per minute per API key.