# Pagination

> Canonical URL: https://docs.mountaya.com/en/apis/conventions/pagination/
> Last updated: 2026-11-27
> Rules for agents: https://docs.mountaya.com/llms.txt#rules-for-agents

Page through a Map Studio API listing with limit and cursor, and follow next_cursor until it is null.

Every Map Studio API listing of what you create pages by cursor. Ask for a page with `limit`, then send the page's `next_cursor` back as `cursor` until it reads `null`.

**cURL**

```bash
CURSOR=""
while : ; do
  PAGE=$(curl -s "https://api.mountaya.com/v1/itineraries?limit=50${CURSOR:+&cursor=$CURSOR}" \
    -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY")
  echo "$PAGE" | jq -r '.data[].name'
  CURSOR=$(echo "$PAGE" | jq -r '.extensions.metadata.pagination.next_cursor // empty')
  [ -z "$CURSOR" ] && break
done
```

**TypeScript**

```typescript
import { Mountaya, paginate } from "@mountaya/client";

const mountaya = new Mountaya({
  credential: { publishableKey: process.env.MOUNTAYA_PUBLISHABLE_KEY ?? "" },
});

// paginate follows every cursor until the last page.
for await (const itinerary of paginate(mountaya.studio.itineraries.getItineraries, {})) {
  console.log(itinerary.name);
}
```

**Python**

```python
import os
import requests

cursor = None
while True:
    page = requests.get(
        "https://api.mountaya.com/v1/itineraries",
        headers={"X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"]},
        params={"limit": 50, "cursor": cursor},
        timeout=30,
    ).json()
    for itinerary in page["data"]:
        print(itinerary["name"])
    cursor = page["extensions"]["metadata"]["pagination"]["next_cursor"]
    if cursor is None:
        break
```

Each page reports where the next one starts. Here, a page of `limit=2`:

**Response (abridged)**

```json
{
  "data": [
    { "id": "44025509-41bc-4038-ac47-05ecbe9a6035", "name": "Docs Tour du Mont-Blanc" },
    { "id": "2660b62b-99ba-4ac8-b269-e034b551e17f", "name": "Docs quickstart 802195" }
  ],
  "extensions": {
    "metadata": {
      "pagination": {
        "limit": 2,
        "next_cursor": "eyJ2IjoxLCJzIjoiLXVwZGF0ZWRfYXQiLCJrIjpbIjIwMjYtMTEtMDlUMDk6MTU6MTUuMTczNTU1WiIsIjI2NjBiNjJiLTk5YmEtNGFjOC1iMjY5LWUwMzRiNTUxZTE3ZiJdLCJmIjoiWDJ3R2hWcms4ZjlfbzJGWiJ9"
      }
    }
  }
}
```

`limit` runs from 1 to 100, and defaults to 50. Only a `null` cursor ends the listing: a short page, even an empty one, can have pages after it.

- Listings that page: itineraries, zones, collections and what a collection holds, members, invitations, publishable keys, invoices, payment methods, and your own memberships and invitations under `/v1/me`. A catalog, such as activities or layers, and a usage series return the whole of what they cover.
- A listing that pages takes `limit`, between 1 and 100 and 50 when omitted, and `cursor`. It reports its page at `extensions.metadata.pagination` (`limit`, `next_cursor`).
- The last page reports `"next_cursor": null`, and that is the only way the end is told: a page shorter than `limit`, or one holding no item at all, can still have one after it, since a page is cut before what your credential may not see is left out of it. Follow every cursor a page names.
- A cursor is opaque and at most 1024 characters. It is bound to the operation, the filters, and the `sort` of the request that issued it, and to the scope it listed. On `getItineraries`, `getZones`, and `getCollections` it is also bound to the access level of the credential it was issued to: a key alone, or a key with a session token naming a user. A session token minted without `user_id` reads at the key's level. Ask for the next page the same way: a cursor sent otherwise, or altered, is a `400` at `["request", "query", "cursor"]`.
- Paging follows the position in the sort order rather than a count, so an item whose sort key does not change is never skipped or served twice, whatever is created or deleted between two pages.
- A query parameter the operation does not declare is a `400`. Sending `offset` or `page` is refused, not ignored.
- What a key alone lists: public items only, and an itinerary or a zone only while it is published. A session token naming a member also lists the organization's private items and drafts.
- In TypeScript, `paginate(method, args, { pageSize, maxPages })` walks a listing to its end; a listing that names a cursor the walk has already followed rejects with `MountayaApiError` rather than read without end.

## Filter and sort

Filters are query parameters named after the field they narrow, such as `status` or `is_private`, and they combine. `sort` takes one key, descending with a leading `-`, such as `sort=-updated_at`.

To mirror a listing, record when you last read it. Then ask for `updated_since` with `sort=updated_at` to read only what changed.

- Filters combine: an item is listed only when it matches every one you send. Two are shared across listings: `updated_since` lists what changed at or after an instant, and `q` matches part of a name without regard to case. A filter narrows what your credential reaches and never widens it.
- `sort` takes one key from the list the operation declares, descending when written with a leading `-`, and ties break on `id`. Each operation's reference names its keys and its default, such as `-updated_at` on itineraries, zones, and collections.
- `updated_since` with `sort=updated_at` walks only what changed since an instant you recorded, so a client that mirrors a listing never reads the whole of it again.

## Next steps

- [Map Studio API reference](https://docs.mountaya.com/en/apis/map-studio/reference.md): Each listing's filters, sort keys, and defaults.
- [Request headers](https://docs.mountaya.com/en/apis/conventions/headers.md): Request ids, caching, and timeouts.
