# Pagination

> How list endpoints page with an opaque cursor, and how to know you reached the end.

URL: https://renzo-digital.com/docs/concepts/pagination

Every list endpoint returns one page at a time and a cursor to the next page.

## Parameters

| Query parameter | Meaning |
| --- | --- |
| `limit` | Page size. Default 20, largest 100. |
| `cursor` | The `next_cursor` of the page before. Leave it out for the first page. |

A `limit` over 100 answers `422` [`validation_failed`](https://renzo-digital.com/docs/error-codes#validation_failed). It is not cut down to 100. A `limit` under 1 fails the same way.

One endpoint has other numbers: `GET /api/v1/market-data/{slug}/bars` defaults to 400 bars and allows up to 1000.

## The page

```bash tab="curl"
curl "$BASE/api/v1/articles?limit=2"
```

```python tab="Python"
import os

import requests

BASE = os.environ["BASE"]

answer = requests.get(f"{BASE}/api/v1/articles", params={"limit": 2})
answer.raise_for_status()
print(answer.json())
```

```js tab="Node.js"
const { BASE } = process.env;

const answer = await fetch(`${BASE}/api/v1/articles?limit=2`);
if (!answer.ok) throw new Error(`HTTP ${answer.status}`);
console.log(await answer.json());
```

```json title="Response"
{
  "items": [
    { "id": "f43679d3-0ab5-5f68-8bda-f0a4c5560594", "slug": "fed-holds-rates-steady-as-inflation-cools" },
    { "id": "3b1e0c55-2f0e-5d7b-9a3c-0e4f8c1d2a6b", "slug": "oil-slips-on-supply-outlook" }
  ],
  "has_more": true,
  "next_cursor": "eyJrIjoiMjAyNi0xMS0wNFQxMzozMDowMFoifQ",
  "limit": 2,
  "total": null,
  "page": null,
  "page_size": null,
  "total_pages": null
}
```

The items above are trimmed.

| Field | Meaning |
| --- | --- |
| `items` | This page, in the endpoint's sort order. |
| `has_more` | `true` when another page exists. |
| `next_cursor` | Send it back as `cursor` for the next page. `null` on the last page. |
| `limit` | The page size that was applied. |
| `total`, `page`, `page_size`, `total_pages` | Always `null` on this API. They exist for numbered pages in Renzo's staff tools. |

## Walk every page

```bash tab="curl"
curl "$BASE/api/v1/articles?limit=100"
# then, for each next page:
curl "$BASE/api/v1/articles?limit=100&cursor=eyJrIjoiMjAyNi0xMS0wNFQxMzozMDowMFoifQ"
```

```python tab="Python"
import requests

BASE = "https://api.uat.renzo-digital.com"

def all_articles():
    params = {"limit": 100}
    while True:
        page = requests.get(f"{BASE}/api/v1/articles", params=params).json()
        yield from page["items"]
        if not page["has_more"]:
            return
        params["cursor"] = page["next_cursor"]
```

```js tab="Node.js"
const BASE = "https://api.uat.renzo-digital.com";

async function* allArticles() {
  let cursor = null;
  do {
    const query = new URLSearchParams({ limit: "100", ...(cursor ? { cursor } : {}) });
    const answer = await fetch(`${BASE}/api/v1/articles?${query}`);
    const page = await answer.json();
    yield* page.items;
    cursor = page.has_more ? page.next_cursor : null;
  } while (cursor);
}
```

## Rules

- **The end.** Stop when `has_more` is `false`. Then `next_cursor` is `null`.
- **An empty page** has `items: []` and `has_more: false`. It is not an error.
- **The cursor is opaque.** Pass it back exactly as you got it. Do not build, edit or decode it. A changed or broken cursor answers `400` [`invalid_cursor`](https://renzo-digital.com/docs/error-codes#invalid_cursor).
- **Keep the other parameters.** Send the same filters and `limit` with every page. A cursor works only with the filters of the page that gave it: a cursor sent with another filter, such as another `type`, `symbol`, `asset_class` or `q`, answers `400` [`invalid_cursor`](https://renzo-digital.com/docs/error-codes#invalid_cursor). Start again from the first page. Date ranges and `locale` are not part of this check.
- **New rows while you page.** The cursor marks a place in the sort order, so you do not see a row twice. A row added before your place appears only when you start again from the first page.
- **No anchors.** Public lists have no `page`, `page_size` or `anchor_id` parameters. The [`anchor_not_found`](https://renzo-digital.com/docs/error-codes#anchor_not_found) and [`anchor_with_cursor`](https://renzo-digital.com/docs/error-codes#anchor_with_cursor) codes belong to staff tools.
