Pagination

Learn how to paginate through large result sets using offset-based pagination.

Overview

List endpoints return paginated results to optimize performance. The API uses offset-based pagination with limit and offset query parameters.

Query Parameters

limit

Maximum number of items to return (1-100). Default: 20.

offset

Number of items to skip before starting to collect the result set. Default: 0.

Example Request

Retrieve the second page of 20 customers:

bash
curl "https://pxb.app/api/public/v1/customers?limit=20&offset=20" \
  -H "X-API-Key: your_api_key_here" \
  -H "X-Organization-ID: your_organization_id_here"

Response Format

Paginated responses include a pagination object with metadata:

json
{
  "message": "Customers retrieved successfully!",
  "content": {
    "customers": [
      { "id": "cust_abc123", "firstName": "Jane", "lastName": "Smith" },
      { "id": "cust_def456", "firstName": "John", "lastName": "Doe" }
    ],
    "pagination": {
      "total": 147,
      "limit": 20,
      "offset": 20,
      "hasMore": true
    }
  }
}

Pagination Metadata

FieldTypeDescription
totalnumberTotal number of items across all pages.
limitnumberThe limit value used for this request.
offsetnumberThe offset value used for this request.
hasMorebooleanWhether more items exist beyond this page.

Iterating Through All Pages

Use the hasMore field to determine when to stop fetching:

javascript
async function fetchAllCustomers() {
  const allCustomers = [];
  let offset = 0;
  const limit = 100;
  let hasMore = true;

  while (hasMore) {
    const response = await fetch(
      `https://pxb.app/api/public/v1/customers?limit=${limit}&offset=${offset}`,
      { headers: { 'X-API-Key': apiKey, 'X-Organization-ID': organizationId } }
    );
    const data = await response.json();

    allCustomers.push(...data.content.customers);
    hasMore = data.content.pagination.hasMore;
    offset += limit;
  }

  return allCustomers;
}

Best Practices

  • Use reasonable page sizes. Request only what you need. Smaller pages mean faster response times.
  • Cache when appropriate. If data doesn't change frequently, cache paginated results locally.
  • Handle empty pages. Always check if the items array is empty before processing.
Copyright © Pixelbase Inc. - All rights reserved.