# Pagination

> Page through list operations with limit and cursor, or let the SDK's paginate helper follow the cursors for you.

URL: https://docs.workwae.com/guides/pagination

List operations answer a page of `items` and a `nextCursor`. Pass the cursor back to read the next page until it is `null`.

## List envelopes

Listings answer one of two envelopes:

| Envelope | Used by |
| --- | --- |
| `{ items, nextCursor }` | Paged lists: accounts, messages, threads, the outbox, calendar events, contacts, templates, webhook attempts and more. |
| `{ items }` | Small bounded lists, answered whole: mailboxes, calendars, contact folders, suppression lists, webhook endpoints, mail merge results. |

## Read the next page

Pass `nextCursor` back as `cursor`. It is `null` on the last page.

```bash tab="cURL"
curl "https://api.workwae.com/v1/accounts?limit=200" \
  -H "Authorization: Bearer $WORKWAE_API_KEY"
# { "items": [...], "nextCursor": "eyJ..." }

curl "https://api.workwae.com/v1/accounts?limit=200&cursor=eyJ..." \
  -H "Authorization: Bearer $WORKWAE_API_KEY"
# { "items": [...], "nextCursor": null }
```

```ts tab="TypeScript"
const first = await workwae.accounts.list({ limit: 200 });
if (first.nextCursor) {
  const second = await workwae.accounts.list({ limit: 200, cursor: first.nextCursor });
}
```

- A cursor is opaque. Do not build or edit one.
- A cursor belongs to its listing and its filters: pass the same filters with it.
- A cursor the listing did not issue answers 400 `invalid_cursor`.

## Page size

`limit` sets the page size. Where an operation names no other size, the default is 50 and the maximum 200.

| Listing | Default | Maximum |
| --- | --- | --- |
| Most listings | 50 | 200 |
| Threads | 25 | 100 |
| Message search | 25 | 100 |
| Calendar events | 100 | 500 |
| Contacts | 100 | 500 |
| Webhook delivery attempts | 50 | 500 |
| Organization directory entries | 100 | 200 |
| Scheduling links | 100 | 1,000 |

Each operation's [reference](/reference) entry states its range.

## Iterate with the SDK

The [TypeScript SDK](/guides/sdk) follows cursors for you. Pass the list method itself, so the item type and filters come from the API contract.

```ts title="TypeScript"
import { pages, paginate } from "@workwae/sdk";

// Every item, following nextCursor to the last page.
for await (const account of paginate(workwae.accounts.list, { limit: 200 })) {
  console.log(account.id);
}

// Page by page, e.g. to checkpoint the cursor.
for await (const page of pages(workwae.messages.list, { accountId, unread: true })) {
  await saveCursor(page.nextCursor);
}
```

Both helpers accept a third `{ signal }` argument, forwarded to every call they make.

## The change feed

`GET /v1/changes` uses the same envelope but never ends: its `nextCursor` is always set, and an empty page means you are caught up. Read it with the SDK's `changes` helper; see [Change feed](/guides/changes).
