# Pagination

> Lists come in pages. limit sets the size, starting_after resumes after the last item, has_more says whether more are left.

Every route that returns several items answers with the same envelope:

```json
{ "object": "list", "data": [...], "has_more": true }
```

## Parameters

- `limit`: how many items per page, from 1 to 100. 20 by default.
- `starting_after`: the `id` of the last item of the previous page. The next page starts right after it.

When `has_more` is `false`, you have everything. The order stays the same from page to page: issues worst first, scans newest first.

The cursor follows an item, not a page number: if a new scan arrives while you go through the list, you never see the same item twice. A `starting_after` that is not in the list answers `400 cursor_invalid`.

## Examples

### Node

```js
const project = "4f9c2a7e-1b3d-4e5f-8a6b-7c8d9e0f1a2b"
const issues = []
let after
do {
  const url = new URL(`https://api.rustine.io/v1/projects/${project}/issues`)
  url.searchParams.set("limit", "100")
  if (after) url.searchParams.set("starting_after", after)
  const res = await fetch(url, {
    headers: { Authorization: `Bearer ${process.env.RUSTINE_API_KEY}` },
  })
  const page = await res.json()
  issues.push(...page.data)
  after = page.has_more ? page.data.at(-1).id : undefined
} while (after)
```

### Python

```python
import os

import requests

project = "4f9c2a7e-1b3d-4e5f-8a6b-7c8d9e0f1a2b"
issues, after = [], None
while True:
    params = {"limit": 100}
    if after:
        params["starting_after"] = after
    page = requests.get(
        f"https://api.rustine.io/v1/projects/{project}/issues",
        headers={"Authorization": f"Bearer {os.environ['RUSTINE_API_KEY']}"},
        params=params,
    ).json()
    issues += page["data"]
    if not page["has_more"]:
        break
    after = page["data"][-1]["id"]
```

### Response: 200 OK

```json
{
  "object": "list",
  "data": [
    { "id": "a3c5e7f9-1b2d-4c6e-8f0a-2b4d6f8a1c3e", "object": "issue" }
  ],
  "has_more": true
}
```
