> 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](/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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
