Pagination
Learn how to paginate through large result sets efficiently.
Overview
All list endpoints in the Mployr API return paginated results. Pagination helps manage large datasets by returning results in manageable chunks.
Query Parameters
| Parameter | Default | Description |
|---|---|---|
| page | 1 | The page number to retrieve (1-indexed) |
| per_page | 15 | Number of items per page (max: 100) |
Response Format
Paginated responses include a pagination object with metadata about the results:
{
"success": true,
"data": [
{ "id": 1, "first_name": "John", "last_name": "Doe" },
{ "id": 2, "first_name": "Jane", "last_name": "Smith" },
{ "id": 3, "first_name": "Bob", "last_name": "Johnson" }
],
"pagination": {
"current_page": 1,
"per_page": 15,
"total": 150,
"last_page": 10,
"from": 1,
"to": 15
}
}Pagination Fields
| Field | Description |
|---|---|
| current_page | Current page number |
| per_page | Items per page |
| total | Total number of items |
| last_page | Total number of pages |
| from | First item index on current page |
| to | Last item index on current page |
Examples
Best Practices
Use Reasonable Page Sizes
The default of 15 items is suitable for most UI displays. For bulk operations, increase to 50-100 items per page for efficiency.
Check last_page Before Fetching
Always check if you've reached the last page before making additional requests to avoid unnecessary API calls.
Handle Empty Results
If the requested page exceeds the total pages, the API returns an empty data array. Handle this case gracefully in your code.
Consider Rate Limits
When fetching many pages, add delays between requests to stay within rate limits. Use larger page sizes to reduce total requests.
Next Steps
Learn how to handle API errors and edge cases.
