# Pagination

Lists are read a page at a time with a cursor, never with page numbers.

Every list endpoint takes two query parameters and answers with the same shape:

| Parameter | Default | What it does |
| --- | --- | --- |
| `limit` | 25 | How many items a page holds, from 1 to 100. |
| `cursor` | none | Where to continue from: the `nextCursor` of the previous page. |

```json title="A page"
{
  "items": [],
  "nextCursor": "0192f0c1-7a3e-7c51-9d2e-4b7f0a1c2d3e"
}
```

`nextCursor` is `null` on the last page. There are no page numbers and no total count, so a list stays correct while items are added during the read.

## Reading every page

<CodeGroup>

```ts title="Node.js"
async function allLeads(): Promise<unknown[]> {
  const leads: unknown[] = []
  let cursor: string | null = null

  do {
    const url = new URL("https://api.leadup.group/v1/leads")

    url.searchParams.set("limit", "100")

    if (cursor) {
      url.searchParams.set("cursor", cursor)
    }

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

    leads.push(...page.items)
    cursor = page.nextCursor
  } while (cursor)

  return leads
}
```

```python title="Python"
def all_leads():
    leads, cursor = [], None
    while True:
        params = {"limit": 100, **({"cursor": cursor} if cursor else {})}
        page = requests.get(f"{BASE_URL}/leads", params=params, headers=HEADERS).json()
        leads += page["items"]
        cursor = page["nextCursor"]
        if not cursor:
            return leads
```

</CodeGroup>

Filters such as `stage` stay the same on every page; only the cursor changes.
