> Index of every page: https://docs.merchantservicedepot.com/llms.txt

# Pagination

> Walk every list with a cursor.

Every list in the API is paginated with a cursor. You ask for a page, and the response tells you whether there's another and where it starts.

## Parameters

| Parameter | Meaning |
| --- | --- |
| `limit` | How many objects per page. Defaults to 10, at most 100. |
| `startingAfter` | An object id. The page starts with the object after it. Leave it out for the first page. |

Lists come newest first. A `limit` that isn't a positive number is ignored, and you get 10. A blank `startingAfter` counts as absent.

```bash title="terminal"
curl "https://payments-api-sandbox.merchantservicedepot.com/v1/customers?limit=25" \
  -H "Authorization: Bearer myela_sk_test_…"

curl "https://payments-api-sandbox.merchantservicedepot.com/v1/customers?limit=25&startingAfter=cus_abc123" \
  -H "Authorization: Bearer myela_sk_test_…"
```

## The list response

```js title="response.json"
{ "object": "list", "data": [ … ], "hasMore": true, "nextCursor": "cus_xyz789" }
```

| Field | Meaning |
| --- | --- |
| `object` | Always "list". |
| `data` | The objects on this page, newest first. |
| `hasMore` | true if there's another page. |
| `nextCursor` | The id to send as startingAfter. Present only when hasMore is true. |

## Walk every page

Ask for the largest page, handle it, and send `nextCursor` back as `startingAfter` until `hasMore` is false.

```ts title="list-all.ts"
const BASE = process.env.MYELA_API_BASE_URL!;
const headers = { Authorization: `Bearer ${process.env.MYELA_API_KEY}` };

let cursor: string | undefined;
do {
  const qs = new URLSearchParams({ limit: '100', ...(cursor ? { startingAfter: cursor } : {}) });
  const page = await (await fetch(`${BASE}/v1/customers?${qs}`, { headers })).json();
  handle(page.data);
  cursor = page.hasMore ? page.nextCursor : undefined;
} while (cursor);
```

## When a cursor stops working

A `startingAfter` that names no object in the list answers `422 invalid_request` with `details.code: UNKNOWN_CURSOR`. It doesn't quietly restart at page one. A deleted object, an object from another list, and an id from another account all look the same. Start the walk again from the first page. More on error codes in [Errors](https://docs.merchantservicedepot.com/docs/platform/errors/).

## Lists that return everything

Two lists always return the full set in one response, with `hasMore: false`:

- `GET /v1/webhook_endpoints`
- `GET /v1/invoices/{id}/attempts`

`GET /v1/webhook_deliveries` is paginated like the rest, and also filters by `endpointId` and `status`.

`GET /v1/invoices` filters by `status`, `customerId`, `createdAfter` (inclusive) and `createdBefore` (exclusive), and `GET /v1/payment_links` by `status`. Send the same filters with every `startingAfter`. A bad filter value is a `422`, never an unfiltered list.

Source: https://docs.merchantservicedepot.com/docs/platform/pagination/
