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

# Pagination

> Walk through large lists with cursor pagination: parameters, response format and iteration in the SDK.

List endpoints use **cursor** (*keyset*) pagination. There is no `page` and `offset` pagination: on tables that only grow, it would get slower and less consistent with every page.

## Parameters

| Parameter | Description |
| - | - |
| `limit` | Items per page, from 1 to 100. The default is 20. |
| `cursor` | The `next_cursor` value of the previous page. |
| `after` | Only on `GET /v1/events`: the `id` of the last event you processed. |

## Response format

```json theme={null}
{
  "data": [
    { "id": "msg_01J8...", "status": "delivered" }
  ],
  "has_more": true,
  "next_cursor": "eyJ..."
}
```

| Field | Description |
| - | - |
| `data` | Items on the page. |
| `has_more` | `true` if there are more pages. |
| `next_cursor` | Cursor of the next page, or `null` on the last one. |

Treat `next_cursor` as an **opaque** value: do not decode it or build it. An invalid cursor returns `422 invalid_cursor`.

> [!NOTE]
>
> On `GET /v1/events` the cursor is the event ID itself, passed in `after`. See [Reconcile events](https://docs.routa.chat/en/webhooks/reconciliation.md).

## Walking through every page

```bash cURL theme={null}
# First page
curl "https://api.routa.chat/v1/messages?limit=50" \
  -H "Authorization: Bearer $ROUTA_API_KEY"

# Next page
curl "https://api.routa.chat/v1/messages?limit=50&cursor=eyJ..." \
  -H "Authorization: Bearer $ROUTA_API_KEY"
```

```ts Node.js theme={null}
// The async iterator fetches the following pages for you.
for await (const message of routa.messages.list({ direction: 'inbound', limit: 50 })) {
  console.log(message.id, message.from, message.content)
}

// To control pagination yourself, ask for one page at a time:
const page = await routa.messages.list({ limit: 20 }).page()
console.log(page.data.length, page.hasMore, page.nextCursor)
```

## Paginated endpoints

| Endpoint | Filters |
| - | - |
| [`GET /v1/messages`](https://docs.routa.chat/en/api-reference/endpoint/messages/list) | `direction` |
| [`GET /v1/events`](https://docs.routa.chat/en/api-reference/endpoint/events/list) | `type`, `after` |
| [`GET /v1/templates`](https://docs.routa.chat/en/api-reference/endpoint/templates/list) | `channel` |
| [`GET /v1/webhook_endpoints/{id}/deliveries`](https://docs.routa.chat/en/api-reference/endpoint/webhooks/list-deliveries) | `state` |

`GET /v1/webhook_endpoints` also uses the `{ data, has_more, next_cursor }` envelope, but returns every endpoint at once (5 per project at most).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.