# Pagination: reading lists page by page

> Every list has data, has_more and next_cursor. Page on with ?cursor=… until has_more is false.

Source: https://flow-marketing.org/en/help/api-pagination · Question: How do I read long lists completely with limit and cursor?

Lists always have the same shape: object “list”, data, has_more and next_cursor. Paging works for videos, renders and speech jobs. All other lists come complete in one response.

Ask for the first page with limit, then send next_cursor as cursor – with the same filters – until has_more is false.

## Shape of every list {#listen-form}

| Field | Meaning |
| --- | --- |
| `object` | always `"list"` |
| `data` | the entries of this page, newest first |
| `has_more` | `true` if there is another page |
| `next_cursor` | value for `cursor` of the next page, otherwise `null` |

**Response 200**

```json
{
  "object": "list",
  "data": [
    { "id": "vid_7Hq2LmN0pQrS3tUv4WxY", "object": "video", "status": "ready" },
    { "id": "vid_2bC9dE8fG7hJ6kL5mN4p", "object": "video", "status": "draft" }
  ],
  "has_more": true,
  "next_cursor": "vid_2bC9dE8fG7hJ6kL5mN4p"
}
```

## Parameters and endpoints {#parameter}

- limit: 1 to 100, default 20. Larger values are set to 100, invalid ones to 20.
- cursor: the next_cursor of the previous response. Today it is the id of the last entry; treat it as opaque text anyway.
- Filters such as status apply per page. Send them again with every page.

| Endpoint | Paged | Filters |
| --- | --- | --- |
| `GET /videos` | yes (`limit`, `cursor`) | `status` |
| `GET /renders` | yes (`limit`, `cursor`) | `status`, `video_id` |
| `GET /speech` | yes (`limit`, `cursor`) | – |
| `GET /webhooks/{id}/deliveries` | only `limit` (default 50), no cursor | – |
| all other lists (`/templates`, `/voices`, `/webhooks`, `/uploads`, `/usage`, `/models` …) | no – complete, `has_more: false` | per endpoint |

> **Note:** Further filters (for example by project, template, date or metadata) do not exist today. The API ignores unknown parameters – filter on those yourself.

## Cursor rules {#cursor-regeln}

- New entries appear on the first page, not on later pages. For “everything since yesterday”, read from the start until you hit known ids.
- If a cursor is unknown or invalid – for example because the video was deleted meanwhile – the API ignores it and returns the first page again. Remember the ids you read and stop as soon as one comes twice.
- An invalid status value is ignored too; you then get the unfiltered list.
- Every page is a read request (class “read”). limit=100 saves requests.

## Reading all pages {#schleife}

**curl**

```bash
# first page
curl -s "https://flow-marketing.org/api/turbo/v1/videos?limit=100&status=ready" \
  -H "Authorization: Bearer $FLOW_API_KEY"

# next page: next_cursor of the previous answer, same filters
curl -s "https://flow-marketing.org/api/turbo/v1/videos?limit=100&status=ready&cursor=vid_2bC9dE8fG7hJ6kL5mN4p" \
  -H "Authorization: Bearer $FLOW_API_KEY"
```

**JavaScript**

```js
async function* listAll(path, params = {}) {
  const seen = new Set()
  let cursor = null
  do {
    const q = new URLSearchParams({ ...params, limit: '100', ...(cursor ? { cursor } : {}) })
    const res = await fetch(`https://flow-marketing.org/api/turbo/v1${path}?${q}`, {
      headers: { Authorization: `Bearer ${process.env.FLOW_API_KEY}` },
    })
    if (!res.ok) throw new Error(`${res.status} ${(await res.json()).code}`)
    const page = await res.json()
    for (const item of page.data) {
      if (seen.has(item.id)) return // cursor was reset (e.g. item deleted) – stop instead of looping
      seen.add(item.id)
      yield item
    }
    cursor = page.has_more ? page.next_cursor : null
  } while (cursor)
}

for await (const video of listAll('/videos', { status: 'ready' })) {
  console.log(video.id, video.status)
}
```

**Python**

```python
import os, requests

BASE = "https://flow-marketing.org/api/turbo/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['FLOW_API_KEY']}"}

def list_all(path, **params):
    seen, cursor = set(), None
    while True:
        q = {**params, "limit": 100, **({"cursor": cursor} if cursor else {})}
        r = requests.get(BASE + path, headers=HEADERS, params=q, timeout=30)
        r.raise_for_status()
        page = r.json()
        for item in page["data"]:
            if item["id"] in seen:  # cursor was reset – stop instead of looping
                return
            seen.add(item["id"])
            yield item
        if not page["has_more"]:
            return
        cursor = page["next_cursor"]

for video in list_all("/videos", status="ready"):
    print(video["id"], video["status"])
```

## See also

- [Videos](https://flow-marketing.org/en/help/api-videos)
- [Renders](https://flow-marketing.org/en/help/api-renders-and-status)
- [Rate limits](https://flow-marketing.org/en/help/api-rate-limits)
