# Pagination

> How lists come back one page at a time, how to follow the cursor to the end, and what makes a cursor stop working.

Source: https://docs.clouduxe.com/api/pagination/

Every list in the API answers one page at a time and hands you a cursor for the
next page. Lists page by keyset, not by offset, so a page never skips or repeats
an object, even while objects are added.

## Ask for a page

Two query parameters control a page:

| Parameter | What it does |
| --- | --- |
| `limit` | How many objects one page holds: 1 to 100, 20 when you leave it out. |
| `cursor` | The `nextCursor` of the page before. Leave it out for the first page. |

`GET /services` (reference: https://docs.clouduxe.com/api/reference/services/list-services/)

```bash
curl https://api.clouduxe.com/v1/services \
  -H "Authorization: Bearer $CLOUDUXE_API_KEY"
```

##### Response (`200`)

```json
{
  "object": "list",
  "data": [
    {
      "object": "service",
      "id": "c3a1f6d2-8b4e-4a9c-b7d5-2e1f0a3c6b8d",
      "type": "vps",
      "status": "active",
      "suspensionReason": null,
      "deletesAt": null,
      "planId": "vps-nvme-4-mumbai",
      "planName": "NVMe VPS 4 GB",
      "region": "mumbai",
      "label": "node1",
      "reference": "client-4471",
      "metadata": {
        "whmcsServiceId": "18342",
        "plan": "starter"
      },
      "firewallAvailable": true,
      "billing": {
        "cycleMonths": 1,
        "price": {
          "amount": 129900,
          "currency": "INR"
        },
        "currentPeriodStart": "2026-12-04",
        "paidThrough": "2027-01-03",
        "cancelAtPeriodEnd": false,
        "endsOn": null
      },
      "server": {
        "powerState": "running",
        "hostname": "node1.acme.example",
        "ipv4": [
          "203.0.113.24"
        ],
        "ipv6": [
          "2001:db8:4f2a::24"
        ],
        "image": {
          "object": "image",
          "id": "ubuntu-24.04",
          "name": "Ubuntu 24.04 LTS",
          "family": "linux"
        },
        "resources": {
          "cpuCores": 2,
          "memoryMb": 4096,
          "diskGb": 80,
          "trafficGb": 4000
        },
        "statusUpdatedAt": "2026-12-04T10:02:41Z",
        "stale": false
      },
      "proxy": null,
      "createdAt": "2026-12-04T09:15:24Z",
      "livemode": true
    },
    {
      "object": "service",
      "id": "4e9b2d7a-1c6f-4b3e-a8d2-7f5c0e9a1b4d",
      "type": "dedicated",
      "status": "provisioning",
      "suspensionReason": null,
      "deletesAt": null,
      "planId": "dedicated-e5-64-limburg",
      "planName": "Dedicated E5 64 GB",
      "region": "limburg",
      "label": "db-primary",
      "reference": "client-4471",
      "metadata": {},
      "firewallAvailable": false,
      "billing": {
        "cycleMonths": 1,
        "price": {
          "amount": 1149900,
          "currency": "INR"
        },
        "currentPeriodStart": "2026-12-04",
        "paidThrough": "2027-01-03",
        "cancelAtPeriodEnd": false,
        "endsOn": null
      },
      "server": {
        "powerState": "unknown",
        "hostname": "db1.acme.example",
        "ipv4": [],
        "ipv6": [],
        "image": null,
        "resources": null,
        "statusUpdatedAt": null,
        "stale": false
      },
      "proxy": null,
      "createdAt": "2026-12-03T14:40:05Z",
      "livemode": true
    },
    {
      "object": "service",
      "id": "a7d4c1e9-3f2b-4d8a-9c6e-0b5a2f7d3e1c",
      "type": "proxy",
      "status": "active",
      "suspensionReason": null,
      "deletesAt": null,
      "planId": "proxy-game-standard",
      "planName": "Protected Proxy Standard",
      "region": null,
      "label": "game-proxy",
      "reference": "client-5102",
      "metadata": {},
      "firewallAvailable": false,
      "billing": {
        "cycleMonths": 1,
        "price": {
          "amount": 249900,
          "currency": "INR"
        },
        "currentPeriodStart": "2026-12-04",
        "paidThrough": "2027-01-03",
        "cancelAtPeriodEnd": false,
        "endsOn": null
      },
      "server": null,
      "proxy": {
        "profile": "fivem",
        "ports": [
          {
            "protocol": "tcp",
            "portStart": 30120,
            "portEnd": 30120
          },
          {
            "protocol": "udp",
            "portStart": 30120,
            "portEnd": 30120
          }
        ]
      },
      "createdAt": "2026-11-28T11:02:19Z",
      "livemode": true
    }
  ],
  "hasMore": true,
  "nextCursor": "eyJsIjoic2VydmljZXMiLCJjIjoiMjAyNi0xMi0wNFQwOToxNToyMloifQ.x7Hq2N"
}
```

## Read the page

A page is a list object:

| Field | What it holds |
| --- | --- |
| `object` | Always `list`. |
| `data` | The objects on this page. |
| `hasMore` | Whether another page follows. |
| `nextCursor` | The cursor for the next page, or `null` when `hasMore` is `false`. |

## Walk every page

Keep asking with the last `nextCursor` until `hasMore` is `false`. At 100
objects a page, the read limit lets one token list about 2,000 objects a second.

```js
let cursor;
do {
  const url = new URL("https://api.clouduxe.com/v1/services");
  url.searchParams.set("limit", "100");
  if (cursor) url.searchParams.set("cursor", cursor);

  const res = await fetch(url, {
    headers: { Authorization: `Bearer ${process.env.CLOUDUXE_API_KEY}` },
  });
  const page = await res.json();
  for (const service of page.data) console.log(service.id);

  cursor = page.hasMore ? page.nextCursor : undefined;
} while (cursor);
```

The Node and PHP SDKs do this for you: their list methods return an iterator
that fetches each page as you reach it.

## When a cursor stops working

A cursor is opaque: do not build or change one. It is tied to the list's
filters and your token's account, and it lasts 24 hours. Using it with other
filters, from another account or after it expires answers `400`
[`cursor_invalid`](https://docs.clouduxe.com/api/errors/#cursor_invalid). Start the list again without a
cursor.
