Pagination
Learn how to paginate through large datasets
Pagination
List endpoints return paginated results to handle large datasets efficiently.
Query Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
limit | integer | 50 | Maximum items per page (max: 100) |
startAfter | string | - | Cursor for the next page |
Response Format
{
"success": true,
"data": {
"customers": [...],
"pagination": {
"limit": 50,
"hasMore": true,
"nextCursor": "abc123xyz"
}
}
}Pagination Fields
| Field | Description |
|---|---|
limit | Number of items requested |
hasMore | Whether more items exist |
nextCursor | ID to use for startAfter in next request |
Example: Fetching All Customers
async function getAllCustomers(orgId, apiKey) {
let allCustomers = [];
let cursor = null;
do {
const url = new URL(`https://developer.servicebay.io/api/v1/organisations/${orgId}/customers`);
url.searchParams.set("limit", "100");
if (cursor) {
url.searchParams.set("startAfter", cursor);
}
const response = await fetch(url, {
headers: { "X-API-Key": apiKey },
});
const data = await response.json();
allCustomers = allCustomers.concat(data.data.customers);
cursor = data.data.pagination.hasMore ? data.data.pagination.nextCursor : null;
} while (cursor);
return allCustomers;
}Best Practices
- Use reasonable page sizes (25-100 items)
- Store the cursor if users might navigate back
- Implement loading states in your UI
- Consider caching results when appropriate