---
docId: doc_36210aa8775946b485f7d77564a1574b
title: Pagination
description: 'How to page through lists in the Platica API with limit, pageToken and nextPageToken.'
---

<script>
  import { Ways, Note } from '$lib/components';
</script>

# Pagination

Send `limit` to choose the page size. To read the next page, pass the returned `nextPageToken` as `pageToken`. Stop when `nextPageToken` is absent or `null`.

```json
{
  "status": "success",
  "data": [
    { "id": "Xq8mTe2LwP4kZ1aB9cDf", "name": "Sales" },
    { "id": "Rk2pLm9QxT7vB4nC1dEf", "name": "Support" }
  ],
  "nextPageToken": "eyJvZmZzZXQiOjIwfQ"
}
```

On lists that use `data`, read their items from that field. Some lists group items by workspace; check each endpoint’s response.

## Example

<Ways tabs="api,sdk">
<Ways.Way name="api">

```bash
curl "https://api.platic.ai/v1/agents?limit=20&pageToken=$NEXT_PAGE_TOKEN" \
  -H "Authorization: Bearer $PLATIC_API_KEY"
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
for await (const agent of platic.agents.iterate()) {
  console.log(agent.name);
}
```

</Ways.Way>
</Ways>

## Parameters

| Parameter | Description |
|-----------|-------------|
| `limit` | How many items you want per page |
| `pageToken` | The `nextPageToken` from the previous page |

The allowed range of `limit` and its default are on each list's page. For example, [List agents](/api-reference/agents/list) takes 1 to 100 and defaults to `20`.

## Rules

- When `nextPageToken` is absent or `null`, there are no more pages.
- Send the `pageToken` with the same filters and the same `?workspace=` (or without it, if the first page didn't carry it). With different ones, the answer is `400`.
- A page can contain fewer than `limit` items and still have another page. If you receive `nextPageToken`, use it to continue.
- Short lists, such as the eval scenarios of a workspace, come complete and without `nextPageToken`.
- On contacts, V1 conversations, chats and campaigns, `pageToken` can't be combined with `offset`: the answer is `400` with the problem in `details.issues`.

<span id="conversations-v2"></span>

## Conversations V2

[List conversations](/api-reference/conversations/list), [the messages of a conversation](/api-reference/conversations/messages) and [Search conversations](/api-reference/conversations/search) use the same `limit`, `pageToken` and `nextPageToken`, with a few extra rules:

| List | `limit` | Order |
|------|---------|-------|
| [List conversations](/api-reference/conversations/list) | 1 to 200, default `50` | `lastActivityAt` (default) or `createdAt`, newest first by default |
| [Messages of a conversation](/api-reference/conversations/messages) | 1 to 100, default `20` | Creation date, newest first by default |
| [Search conversations](/api-reference/conversations/search) | 1 to 100, default `10` | Rank order, up to `candidateLimit` (250 by default) |

```json
{
  "status": "success",
  "data": [
    { "id": "conv_1", "contactName": "Ana", "operation": "supervised" }
  ],
  "nextPageToken": "eyJrIjoiY29udl8xIn0",
  "pagination": { "limit": 20, "returnedCount": 1, "hasMore": true },
  "meta": { "fields": ["id", "contactName", "operation"], "include": [], "requestId": "req_123" }
}
```

- **`nextPageToken` is always present.** It is `null` on the last page. `pagination.hasMore` says the same thing.
- **Follow the token, not the page length.** A page can be shorter than `limit`, or even empty, and still have a `nextPageToken`: conversations you can't see or that were deleted are left out.
- **Same filters, same order, same workspace.** A `pageToken` sent with other filters, another order, another workspace or another credential answers `400 INVALID_CURSOR`. `limit`, `fields` and `include` may change between pages.
- **No `offset`.** V2 lists only page with tokens.
- **The list is live.** A conversation whose `lastActivityAt` changes between pages can move position. Messages, sorted by their creation date, don't move.

<span id="search-sessions"></span>

### Search sessions

A search ranks its results once and keeps that ranking for **15 minutes**. Send the same body with `pageToken` to read the next page. After 15 minutes the token answers `410 SEARCH_SESSION_EXPIRED`: repeat the search without `pageToken`. Each page is checked again, so a conversation deleted or out of your reach since the first page is left out. Pages never go past `candidateLimit`.

<Note type="info">

Some contact, V1 conversation and message lists group their items by workspace. Each endpoint reference shows where to find them. See [Responses](/api-reference/responses).

</Note>
