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

# Pagination

> Read collections page by page

Every collection returns the same envelope:

```json theme={null}
{
  "data": [{ "id": "l44e15irdq4db30i77cgphhx" }],
  "nextCursor": "eyJhdCI6IjIwMjYtMDktMTRUMTA6MzI6MDAuMDAwWiJ9"
}
```

| Parameter | Notes |
| - | - |
| `limit` | Page size, from 1 to 100. Defaults to 50 |
| `cursor` | The previous page's `nextCursor` |

`nextCursor` is `null` on the last page.

## Read every page

<CodeGroup>
  ```typescript paginate.ts theme={null}
  async function* pages<T>(path: string): AsyncGenerator<T> {
    let cursor: string | null = null;

    do {
      const url = new URL(`https://inboxapp.com/api/v2${path}`);
      url.searchParams.set("limit", "100");
      if (cursor) url.searchParams.set("cursor", cursor);

      const response = await fetch(url, {
        headers: { Authorization: `Bearer ${process.env.INBOX_API_TOKEN}` },
      });

      if (!response.ok) {
        const error = await response.json();
        throw new Error(`${error.code}: ${error.message} (${error.requestId})`);
      }

      const page = await response.json();
      yield* page.data;
      cursor = page.nextCursor;
    } while (cursor);
  }

  for await (const thread of pages<{ id: string }>("/threads?folder=all")) {
    console.log(thread.id);
  }
  ```

  ```bash cURL theme={null}
  curl "https://inboxapp.com/api/v2/threads?folder=all&limit=100" \
    -H "Authorization: Bearer $INBOX_API_TOKEN"

  curl "https://inboxapp.com/api/v2/threads?folder=all&limit=100&cursor=eyJhdCI6IjIwMjYtMDktMTRUMTA6MzI6MDAuMDAwWiJ9" \
    -H "Authorization: Bearer $INBOX_API_TOKEN"
  ```
</CodeGroup>

## Rules

* **A cursor is opaque.** Don't parse or build one.
* **Keep the filters.** A cursor is only valid with the filters it was issued for. Changing them fails with `400 invalidCursor`.
* **Out-of-range `limit` is rejected**, not clamped.

## Order

| Collection | Order |
| - | - |
| `GET /threads` | Inbox order, newest first. `order=asc` reverses it |
| `GET /threads/{threadId}/messages` | `createdAt`, newest first. `order=asc` reverses it |
| `GET /contacts`, `/account-links`, `/members` | `createdAt`, oldest first |

## Event replay

`GET /events` pages by sequence number instead of a cursor: pass `afterSeq`, and continue from `lastSeq` while `hasMore` is true. See [Replay missed events](/v2/webhooks/overview#replay-missed-events).


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