> ## Documentation Index
> Fetch the complete documentation index at: https://developers.loyaltylion.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pagination

## Cursor-based pagination

Most API endpoints return a `cursor` which can be used to get the previous or next page of results. This is usually better than using `since_id` to paginate because:

* the results are always ordered in descending order (newest first)
* no need to manually keep track of the last ID
* `null` cursor indicate that no more results are available
* the cursor includes any filters applied in the initial request, so subsequent requests need only provide the single `cursor` param to retrieve the next page with the same filters applied

These endpoints include a `cursor` property in the response object, for example:

```json theme={null}
{
  "customers": [...],
  "cursor": {
    "prev": null,
    "next": "eyJsYXN0SWQiOjE0NjgsImRpcmVjdGlvbiI6Im5leHQifQ"
  }
}
```

If either cursor is `null` it means there are no more pages available in that direction.

<Tip>
  Cusors are also included in the `Link` header of the response. This is useful
  if you are retrieving results in CSV format, in which case the response body
  will not include the cursors
</Tip>

To retrieve the previous or next page of results, pass the cursor as a `cursor` query param. You **do not** need to pass any other params; if you initially provided other params to filter the response, these will be part of the cursor already, and any other filtering params will be ignored. Only the `limit` parameter will be recognized.

For example:

```bash theme={null}
curl \
  --url 'https://api.loyaltylion.com/v2/customers?cursor=eyJsYXN0SWQiOjE0NjgsImRpcmVjdGlvbiI6Im5leHQifQ' \
  --header 'Content-Type: application/json'
```

## `since_id` parameter pagination

All collection endpoints support a `since_id` parameter.

When a `since_id` is specified, the collection is ordered by `id` ascending, and contains only resources with an id greater than the specified `since_id`.

To fully paginate through a collection, follow the algorithm:

1. Initialize your `since_id` to `0`
2. Specify a `limit`
3. Make a request with your current `since_id` and `limit`
4. If the number of resources returned is less than your `limit`, finish
5. Otherwise, set `since_id` equal to the `id` of the last resource in the response and repeat

### Example

<Note>Some data is omitted from the example responses for clarity.</Note>

<CodeGroup>
  ```bash First request theme={null}
  curl \
  --url 'https://api.loyaltylion.com/v2/customers?since_id=0&limit=2' \
  --header 'Content-Type: application/json'
  ```

  ```json First response theme={null}
  {
  "customers": [
      {
      "id": 123,
      "merchant_id": "2134606599",
      "email": "jessica@example.com"
      },
      {
      "id": 168,
      "merchant_id": "6246262",
      "email": "kevin@example.com"
      }
  ]
  }
  ```

  ```bash Second request theme={null}
  curl \
  --url 'https://api.loyaltylion.com/v2/customers?since_id=168&limit=2' \
  --header 'Content-Type: application/json'
  ```

  ```json Second response theme={null}
  {
  "customers": [
      {
      "id": 185,
      "merchant_id": "5234262462",
      "email": "larry@example.com"
      }
  ]
  }
  ```
</CodeGroup>
