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

# Pagination

> Long lists come back one page at a time.

Long lists come back in pages, like pages of search results. This applies to your campaigns, a campaign's leads, a lead's messages, and opt-outs.

| Parameter | What it does |
| - | - |
| `limit` | Items per page, from 1 to 200. Defaults to 50. A value over 200 is treated as 200 rather than rejected. |
| `cursor` | Which page to fetch. Leave it out for the first page; after that, pass `pagination.nextCursor` from the previous response. |

Every list response includes a `pagination` object:

| Field | Meaning |
| - | - |
| `limit` | The page size used. |
| `total` | How many items there are across all pages. |
| `hasMore` | `true` if another page follows. |
| `nextCursor` | Pass this as `cursor` to get the next page. `null` on the last page. |

Pass `nextCursor` back exactly as you received it, and don't build or edit a cursor yourself: its format differs between endpoints. `/opt-outs` rejects a cursor it didn't issue with `400 invalid_params`. The other list endpoints don't check, so an edited cursor can return the wrong page.

If a list is larger than the endpoint can read, the request fails with `413 result_too_large` instead of returning part of it, so `total` and `hasMore` always describe the whole list.

## Example: fetch every page

```javascript theme={null}
const BASE_URL = "https://api-production-a5d3.up.railway.app/v1";

async function fetchAll(path, apiKey) {
  const rows = [];
  let cursor = null;
  do {
    const url = new URL(BASE_URL + path);
    url.searchParams.set("limit", "200");
    if (cursor) url.searchParams.set("cursor", cursor);

    const response = await fetch(url, {
      headers: { Authorization: `Bearer ${apiKey}` },
    });
    const body = await response.json();
    if (!response.ok) {
      throw new Error(`${body.error.code}: ${body.error.message}`);
    }

    rows.push(...body.data);
    cursor = body.pagination.nextCursor;
  } while (cursor);
  return rows;
}

const apiKey = process.env.RECLOSED_API_KEY;
const campaigns = await fetchAll("/campaigns", apiKey);
```


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