# Pagination

> Cursor pagination of REST API lists - items, nextCursor and limit.

Lists that can grow long return a page and a cursor:

```json
{ "items": [ … ], "nextCursor": "eyJ0IjoiMjAyNi0xMS0xMFQxNDowMjowMFoifQ" }
```

- `limit` sets the page size: 50 by default, at most 200.
- Pass `nextCursor` as `cursor` to get the next page, with the same filters. `nextCursor` is `null` on the last page.
- A cursor is opaque: do not build or change one. A cursor from another list answers `400 request.invalid_cursor`.

```sh title="Every incident of a project"
cursor=""
while :; do
  page=$(curl -fsS "https://app.monitorly.cloud/api/v1/projects/$PROJECT/incidents?limit=200${cursor:+&cursor=$cursor}" \
    -H "Authorization: Bearer $MONITORLY_TOKEN")
  echo "$page" | jq -c '.items[]'
  cursor=$(echo "$page" | jq -r '.nextCursor // empty')
  [ -n "$cursor" ] || break
done
```

## Which lists page

These lists page, with `cursor` and `limit`:

| List                                                                                             | Operation                                             |
| ------------------------------------------------------------------------------------------------ | ----------------------------------------------------- |
| [List checks](https://docs.monitorly.cloud/api/reference/operations/list-checks.md)                                            | `GET /api/v1/projects/{projectId}/checks`             |
| [List check runs](https://docs.monitorly.cloud/api/reference/operations/list-check-runs.md)                                    | `GET /api/v1/checks/{checkId}/runs`                   |
| [List incidents](https://docs.monitorly.cloud/api/reference/operations/list-incidents.md)                                      | `GET /api/v1/projects/{projectId}/incidents`          |
| [List audit events](https://docs.monitorly.cloud/api/reference/operations/list-audit-events.md)                                | `GET /api/v1/workspaces/{workspaceId}/audit`          |
| [List a page's email subscribers](https://docs.monitorly.cloud/api/reference/operations/list-status-page-email-subscribers.md) | `GET /api/v1/status-pages/{pageId}/subscribers/email` |

Every other list (projects, nodes, servers, maintenance windows, status pages, alert channels, members, invites, API tokens, escalation policies) answers a plain JSON array with every item at once and takes no `cursor`. [Get response times](https://docs.monitorly.cloud/api/reference/operations/get-check-latency.md) accepts `cursor` and `limit` but ignores them: it answers the whole range.

Filters of each list are in the [REST reference](https://docs.monitorly.cloud/api/reference.md).
