> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getaptly.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pagination

> How to paginate through list endpoints and detect when you have reached the last page.

List endpoints in the Aptly API return results one page at a time. Use the `page` query parameter to walk through all records.

## Parameters

| Parameter | Type    | Default | Description                                                                              |
| --------- | ------- | ------- | ---------------------------------------------------------------------------------------- |
| `page`    | integer | `0`     | Zero-indexed page number. Start at `0` and increment by `1` for each subsequent request. |
| `limit`   | integer | `50`    | Number of records per page. Maximum is `100`.                                            |

## Example

```bash theme={null}
# First page
curl "https://core-api.getaptly.com/api/board/{boardId}?page=0&limit=50" \
  -H "x-token: YOUR_API_KEY"

# Second page
curl "https://core-api.getaptly.com/api/board/{boardId}?page=1&limit=50" \
  -H "x-token: YOUR_API_KEY"
```

## Detecting the last page

The response includes a `total` field representing the total number of records on the board. You have reached the last page when the following is true:

```js theme={null}
(page + 1) * limit >= total
```

Example: if `total` is `112` and your `limit` is `50`, you need three pages (pages `0`, `1`, and `2`). On page `2` you will receive the remaining `12` records.

## Iterating all records

To collect all cards on a board:

1. Fetch page `0` and read `total` from the response
2. Calculate the number of pages: `Math.ceil(total / limit)`
3. Fetch each subsequent page until you have all records

<Note>
  Avoid storing page numbers as persistent cursors. If cards are added or removed between requests, page boundaries can shift. For reliable sync, use a timestamp filter if available or reconcile by card ID after fetching all pages.
</Note>
