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

# Pagination

> Page through lists with page[number] and page[size].

Lists are paginated. Pick the page with `page[number]` and its length with `page[size]`.

**page\[number]** `integer` (default: 1)

The page, starting at 1. A page past the end returns an empty `data`.

**page\[size]** `integer` (default: 30)

Items per page, 1 to 30. Larger values become 30.

```bash cURL theme={null}
curl --globoff "https://api.followr.ai/api/companies/1287/postGroups?page[number]=2&page[size]=10" \
  --header "Authorization: Bearer $FOLLOWR_API_KEY" \
  --header "Accept: application/json"
```

> [!NOTE]
>
> `curl` treats square brackets as a pattern. Pass `--globoff` (`-g`), or encode them: `page%5Bnumber%5D=2`.

## The response

Items come in `data`, links to other pages in `links`, and counts in `meta`.

```json theme={null}
{
  "data": [
    { "id": 88440, "title": "Holiday hours" }
  ],
  "links": {
    "first": "https://api.followr.ai/api/companies/1287/postGroups?page%5Bsize%5D=10&page%5Bnumber%5D=1",
    "last": "https://api.followr.ai/api/companies/1287/postGroups?page%5Bsize%5D=10&page%5Bnumber%5D=12",
    "prev": "https://api.followr.ai/api/companies/1287/postGroups?page%5Bsize%5D=10&page%5Bnumber%5D=1",
    "next": "https://api.followr.ai/api/companies/1287/postGroups?page%5Bsize%5D=10&page%5Bnumber%5D=3"
  },
  "meta": {
    "current_page": 2,
    "from": 11,
    "last_page": 12,
    "path": "https://api.followr.ai/api/companies/1287/postGroups",
    "per_page": 10,
    "to": 20,
    "total": 112,
    "links": []
  }
}
```

| Field | Meaning |
| - | - |
| `links.next` | The next page, with your page size, filters, sort and includes. `null` on the last page. |
| `links.prev` | The previous page. `null` on the first page. |
| `meta.total` | Items in the whole list. |
| `meta.last_page` | The number of the last page. |
| `meta.links` | Numbered page links, handy for a pager. |

## Get every page

Follow `links.next` until it is `null`. It already carries your query, so request it as is.

```python Python theme={null}
import os
import requests

session = requests.Session()
session.headers.update({
    "Authorization": f"Bearer {os.environ['FOLLOWR_API_KEY']}",
    "Accept": "application/json",
})

url = "https://api.followr.ai/api/companies/1287/postGroups"
params = {"page[size]": 30, "sort": "-created_at"}

while url:
    response = session.get(url, params=params, timeout=30)
    response.raise_for_status()
    body = response.json()

    for group in body["data"]:
        print(group["id"], group["title"])

    url = body["links"]["next"]
    params = None  # the next link already has the query string
```

```javascript JavaScript theme={null}
const headers = {
  Authorization: `Bearer ${process.env.FOLLOWR_API_KEY}`,
  Accept: "application/json",
};

let url = new URL("https://api.followr.ai/api/companies/1287/postGroups");
url.searchParams.set("page[size]", "30");
url.searchParams.set("sort", "-created_at");

while (url) {
  const response = await fetch(url, { headers });
  if (!response.ok) {
    throw new Error(`Followr API error ${response.status}: ${await response.text()}`);
  }

  const { data, links } = await response.json();
  for (const group of data) {
    console.log(group.id, group.title);
  }

  url = links.next;
}
```

```php PHP theme={null}
<?php

$url = 'https://api.followr.ai/api/companies/1287/postGroups?' . http_build_query([
    'page' => ['size' => 30],
    'sort' => '-created_at',
]);

while ($url !== null) {
    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [
            'Authorization: Bearer ' . getenv('FOLLOWR_API_KEY'),
            'Accept: application/json',
        ],
    ]);
    $body = json_decode(curl_exec($ch), true);
    $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
    curl_close($ch);

    if ($status !== 200) {
        throw new RuntimeException("Followr API error {$status}");
    }

    foreach ($body['data'] as $group) {
        echo $group['id'], ' ', $group['title'], PHP_EOL;
    }

    $url = $body['links']['next'];
}
```

## Good practice

* **Sort when you page.** Without `sort`, the order isn't guaranteed and items can move between pages. Sort by `id` or `created_at`.
* **Filter instead of paging** to find things. See [Filtering, sorting and including](https://docs.followr.ai/api/filtering-sorting-and-including.md).
* **For a full sync**, sort by `id` ascending and remember the last ID you processed: new items can shift later pages.
* Every page counts against the [rate limit](https://docs.followr.ai/api/rate-limits.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.