Pagination

The ServiceM8 API implements cursor-based pagination for handling large datasets efficiently.

How It Works

To retrieve paginated results:

Initial Request: Include the cursor parameter with a value of -1 in your API request

Response: Each successful response returns up to 1,000 records

Next Page: The response includes an x-next-cursor HTTP header containing a UUID for the next page

Subsequent Requests: Use the UUID from x-next-cursor as the cursor parameter value in your next request

Final Page: When you've reached the last page, the x-next-cursor header will be absent from the response

Example Implementation

GET /api_1.0/job.json?cursor=-1

Response Headers:
x-next-cursor: 550e8400-e29b-41d4-a716-446655440000

Next Request:
GET /api_1.0/job.json?cursor=550e8400-e29b-41d4-a716-446655440000

Continue this pattern until no x-next-cursor header is returned, indicating you've retrieved all available records.

Controlling Page Size with $top

By default each page contains up to 1,000 records. Add the $top parameter to request smaller pages:

GET /api_1.0/job.json?cursor=-1&$top=100

  • $top accepts a whole number from 1 to 999. Any other value is ignored and the default page size of 1,000 applies.
  • The x-next-cursor header works the same way. Keep sending the same $top value with each subsequent request.

Limiting Results Without a Cursor

$top can also be used without the cursor parameter to return only the first matching records:

GET /api_1.0/job.json?$top=10

This is useful together with $filter and $sort when you only need a few records, for example the 10 most recently modified jobs:

GET /api_1.0/job.json?$sort=edit_date desc&$top=10

  • $top must be a whole number greater than 0. Any other value is ignored and all matching records are returned.
  • No x-next-cursor header is returned, so there is no way to fetch the records after the first $top. To read every record, use cursor-based pagination instead.
  • $sort cannot be combined with cursor. Use $sort with $top when you need the first records in a specific order.

📘

Using TypeScript?

Use the ServiceM8 SDK and you'll get pagination support automatically.

https://www.npmjs.com/package/servicem8


Did this page help you?