---
title: "Pagination"
description: "How UserLoop API lists are paged with an opaque cursor, what each list endpoint returns, and a complete loop in JavaScript and Python."
---

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

# Pagination

Every list endpoint returns one page at a time in the same envelope. To read the next page, send the page's `next_cursor` back as `cursor`, with the same query, until `has_more` is `false`.

## The list envelope

```json
{
  "data": [ … ],
  "has_more": true,
  "next_cursor": "eyJ2IjoxLCJ0IjoibGlzdF9zdXJ2ZXlzIiwiYyI6IjUwIiwicSI6ImUzYjBjNDQyIn0",
  "total": 132
}
```

| Field | What it is |
| --- | --- |
| `data` | The items on this page, in the endpoint's order: newest first for surveys, responses and written answers, most recently active first for customers. |
| `has_more` | `true` when there is another page. |
| `next_cursor` | What to send as `cursor` for the next page; `null` on the last page. |
| `total` | Surveys, exports and PDF reports only: how many items match, across every page. |
| `partial` | Responses, written answers and customers only: `true` when a filter matched more rows than UserLoop read, so older matches may be missing. Narrow the date range or the filters to read them all. |

A few lists carry one more field: `GET /written-answers` has `theme` when you list by theme, `GET /exports` and `GET /reports/pdf` have `note`, and `GET /webhooks` has `limit`, the most webhook endpoints an organisation may have.

New fields may be added to the envelope and to items within v1, so ignore fields you don't know.

## Cursors

- **Treat a cursor as opaque.** Pass back `next_cursor` exactly as it came. Don't build or change one.
- **Keep the query the same.** A cursor belongs to one endpoint and one set of filters. Use it on another endpoint, or change a filter between pages, and you get `400` `invalid_cursor`. To change the filters, start again without `cursor`.
- **You may change `limit` between pages.** It is the only parameter a cursor isn't tied to.
- **Read pages in order.** Each cursor continues from the page that gave it.

## Page size

Set the page size with `limit`. Without it, each endpoint uses its default.

| Endpoint | `limit` | Default | Pages with `cursor` |
| --- | --- | --- | --- |
| `GET /surveys` | 1 to 100 | 50 | Yes |
| `GET /responses` | 1 to 50 | 20 | Yes |
| `GET /written-answers` | 1 to 100 | 30 | Yes |
| `GET /customers` | 1 to 100 | 25 | Yes |
| `GET /exports` | 1 to 30 | 20 | No: it holds the newest 30 exports |
| `GET /reports/pdf` | 1 to 30 | 20 | No: it holds the newest 30 reports |
| `GET /sites` | none | all | No |
| `GET /webhooks` | none | all | No |
| `GET /webhooks/samples/{event_type}` | 1 to 10 | 3 | No |

The lists that don't take `cursor` return everything in one page, with `has_more` set to `false`. Read an older export or report by its ID, with `GET /exports/{export_id}` or `GET /reports/pdf/{report_id}`.

A `limit` outside its range gets `400` `invalid_request`.

## Read every page

Both examples read every live survey. Set `USERLOOP_API_KEY` to your key (`ulk_live_…`) first. They stop on the first error; [Rate limits and safe retries](https://docs.userloop.io/developers/api/rate-limits-and-retries/) shows how to retry.

### JavaScript

Save as `list-surveys.mjs` and run `node list-surveys.mjs` (Node 18 or later).

```js
const BASE = "https://app.userloop.io/api/v1";
const KEY = process.env.USERLOOP_API_KEY;

async function listAll(path, params = {}) {
  const items = [];
  let cursor = null;
  do {
    const query = new URLSearchParams(params);
    if (cursor) query.set("cursor", cursor);
    const res = await fetch(`${BASE}${path}?${query}`, {
      headers: { Authorization: `Bearer ${KEY}` },
    });
    const body = await res.json();
    if (!res.ok) throw new Error(`${res.status} ${body.code}: ${body.detail}`);
    items.push(...body.data);
    cursor = body.has_more ? body.next_cursor : null;
  } while (cursor);
  return items;
}

const surveys = await listAll("/surveys", { status: "active", limit: "100" });
for (const survey of surveys) console.log(survey.id, survey.title);
console.log(`${surveys.length} live surveys`);
```

### Python

Save as `list_surveys.py`, install `requests` (`pip install requests`) and run `python list_surveys.py`.

```python
import os

import requests

BASE = "https://app.userloop.io/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['USERLOOP_API_KEY']}"}


def list_all(path, params=None):
    params = dict(params or {})
    while True:
        response = requests.get(BASE + path, headers=HEADERS, params=params, timeout=30)
        body = response.json()
        if not response.ok:
            raise RuntimeError(f"{response.status_code} {body['code']}: {body['detail']}")
        yield from body["data"]
        if not body["has_more"]:
            return
        params["cursor"] = body["next_cursor"]


surveys = list(list_all("/surveys", {"status": "active", "limit": 100}))
for survey in surveys:
    print(survey["id"], survey["title"])
print(len(surveys), "live surveys")
```

You should see one line per live survey, its ID and title, then the count. The same function reads any list that takes `cursor`: for example `listAll("/responses", { range: "7d", limit: "50" })` reads last week's responses.

Each page is one request against your [rate limit](https://docs.userloop.io/developers/api/rate-limits-and-retries/) of about 120 requests a minute per key, so use the largest `limit` the endpoint allows when you read a lot.

## Related

- [List and search responses](https://docs.userloop.io/developers/api/list-and-search-responses/)
- [Errors](https://docs.userloop.io/developers/api/errors/)
- [API reference](https://docs.userloop.io/developers/api/reference/)

Source: https://docs.userloop.io/developers/api/pagination/index.mdx
