Pagination

Learn how to paginate through large datasets

Pagination

List endpoints return paginated results to handle large datasets efficiently.

Query Parameters

ParameterTypeDefaultDescription
limitinteger50Maximum items per page (max: 100)
startAfterstring-Cursor for the next page

Response Format

{
  "success": true,
  "data": {
    "customers": [...],
    "pagination": {
      "limit": 50,
      "hasMore": true,
      "nextCursor": "abc123xyz"
    }
  }
}

Pagination Fields

FieldDescription
limitNumber of items requested
hasMoreWhether more items exist
nextCursorID 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

On this page