# Pagination

> How lists come back, and how to walk through all of one with a cursor.

On the web: https://www.aeyho.com/docs/api/pagination

## How lists come back

A list answers with the items and a cursor for the next page:

```json
{ "data": [ ... ], "nextCursor": "MjA" }
```

- `limit` sets the page size: 1 to 100, 20 when left out.
- `cursor` asks for the page after the one that gave it.
- `nextCursor` is `null` on the last page.

A cursor is opaque. Don't build one, change one or keep one for long: start again from the first page instead.

## Walking a list

```js
let cursor = null;
do {
  const url = new URL("https://www.aeyho.com/api/v1/reels");
  url.searchParams.set("limit", "100");
  if (cursor) url.searchParams.set("cursor", cursor);
  const res = await fetch(url, { headers: { Authorization: `Bearer ${process.env.AEYHO_KEY}` } });
  const page = await res.json();
  for (const reel of page.data) console.log(reel.id, reel.status);
  cursor = page.nextCursor;
} while (cursor);
```

## The lists

| List | Order | Notes |
|---|---|---|
| `GET /brands` | Last changed first | |
| `GET /brands/{brandId}/ideas` | The plan's order | |
| `GET /brands/{brandId}/taste` | Oldest first | |
| `GET /reels` | Last changed first | |
| `GET /reels/{reelId}/versions` | Oldest first | |
| `GET /reels/{reelId}/comments` | By moment or slide, then oldest first | Add `status=open`, `done` or `wontfix` to filter. |
| `GET /webhooks` | Newest first | |
| `GET /webhooks/{webhookId}/deliveries` | Newest first | The last 50, in one page. |

`POST /brands/{brandId}/plan` answers in the same shape, with every planned idea in one page.

## Try it

```bash
curl "https://www.aeyho.com/api/v1/reels?limit=2" \
  -H "Authorization: Bearer $AEYHO_KEY"
```
