> For the complete documentation index, see [llms.txt](https://docs.opensoutheners.com/oss/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.opensoutheners.com/oss/flex-url/building-urls/pagination.md).

# Pagination

Build page\[number], page\[size], and page\[cursor] query parameters.

`page()`, `pageSize()`, and `pageCursor()` set the three sub-keys apiable's pagination strategies read from the `page` bucket. Use whichever apply to the active strategy — length-aware and simple pagination use `number`/`size`; cursor pagination uses `cursor` (and optionally `size`).

{% tabs %}
{% tab title="TypeScript" %}

```ts
flexUrl('/posts').page(2).pageSize(25);
// /posts?page[number]=2&page[size]=25

flexUrl('/posts').pageCursor('eyJpZCI6MTB9');
// /posts?page[cursor]=eyJpZCI6MTB9
```

{% endtab %}

{% tab title="PHP" %}

```php
FlexUrl::make('/posts')->page(2)->pageSize(25);
// /posts?page[number]=2&page[size]=25

FlexUrl::make('/posts')->pageCursor('eyJpZCI6MTB9');
// /posts?page[cursor]=eyJpZCI6MTB9
```

{% endtab %}
{% endtabs %}

## Reading pagination back

`getPage()`/`getPageSize()` only return a value when the URL actually carried an integer — a URL is user-supplied, so `page[number]=abc` is entirely possible. A non-integer (or absent) value returns `undefined`/`null` rather than `NaN` or a silently-wrong `0`, so it can't poison arithmetic downstream.

{% tabs %}
{% tab title="TypeScript" %}

```ts
flexUrl('/posts?page[number]=2&page[size]=25').getPage();     // 2
flexUrl('/posts?page[number]=2&page[size]=25').getPageSize(); // 25
flexUrl('/posts?page[number]=abc').getPage();                 // undefined
flexUrl('/posts?page[cursor]=eyJpZCI6MTB9').getPageCursor();  // "eyJpZCI6MTB9"
```

{% endtab %}

{% tab title="PHP" %}

```php
FlexUrl::make('/posts?page[number]=2&page[size]=25')->getPage();     // 2
FlexUrl::make('/posts?page[number]=2&page[size]=25')->getPageSize(); // 25
FlexUrl::make('/posts?page[number]=abc')->getPage();                 // null
FlexUrl::make('/posts?page[cursor]=eyJpZCI6MTB9')->getPageCursor();  // "eyJpZCI6MTB9"
```

{% endtab %}
{% endtabs %}

## Consuming a paginated response

Advancing to a `links.next` page from an apiable JSON:API response is covered under [JSON:API Links Helper](https://docs.opensoutheners.com/oss/flex-url/advanced/json-api-links.md) (TypeScript-only — see that page for the `nextUrl()`/`prevUrl()` helpers, which return a ready-made `FlexUrl` including cursor-based pagination).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.opensoutheners.com/oss/flex-url/building-urls/pagination.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
