# Script pagination

## Overview

If a standard pagination type can't meet your pagination requirements, you can create a [custom script](/product-documentation/developer-hub/custom-scripting/pagination-scripts.md) and apply this as the `pagination method` for endpoints.

## How it works

* [Script development](#script-development)
* [Pagination parameters](#pagination-parameters)
* [Applying a pagination script](#applying-a-pagination-script)

### Script development

Pagination scripts are [added and tested via the custom scripts option](/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts.md) in the usual way. Content for these scripts depends on your requirements and the API for your connector. As with any script, you can include references to [flow variables](/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables.md), [meta-variables](/product-documentation/process-flows/building-process-flows/dynamic-variables/metadata-variables.md), and [payload variables](/product-documentation/process-flows/building-process-flows/dynamic-variables/payload-variables.md).

{% hint style="info" %}
For more information about developing pagination scripts, please see our [pagination scripts](/product-documentation/developer-hub/custom-scripting/pagination-scripts.md) page.
{% endhint %}

### Pagination parameters

For standard pagination methods, parameters are defined when a method is selected for the endpoint. For example, the `next page url` pagination method prompts for a `next page field` parameter:

<div align="left"><figure><img src="/files/cDWprEDdIxQDfYcqr2A8" alt=""><figcaption></figcaption></figure></div>

If you're developing a script to handle pagination, you can either:

* define pagination parameters as [required or optional URL parameters](/product-documentation/developer-hub/connector-builder/building-your-own-connector/4-endpoints/endpoint-options/url.md#endpoint-parameters)
* define pagination parameters in your script

### Applying a pagination script&#x20;

To apply a script that you've developed for pagination, follow the steps below.

**Step 1**\
From the endpoint pagination tab, select the `script` pagination method:

<div align="left"><figure><img src="/files/A2MWOJZn67TbA9nV0W6j" alt=""><figcaption></figcaption></figure></div>

**Step 2**\
Use the `select a script` field to choose the required pagination script - for example:

<div align="left"><figure><img src="/files/ILelN2N4HNTkVxsP6dQS" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
All scripts created for your company are available for selection. If you select a script that isn't deployed, it will be deployed the first time this endpoint is used (in this case the first request may take longer than usual).
{% endhint %}

**Step 3**\
Use the version field to choose which version of the selected script to use - for example:

<div align="left"><figure><img src="/files/YOtcxgRopCn7gYYjNLyd" alt=""><figcaption></figcaption></figure></div>

{% hint style="warning" %}
If your script is updated in future, remember to come back here and (if appropriate) select the later version.&#x20;
{% endhint %}

**Step 4**\
Click save and go back to return the list of endpoints:

<div align="left"><figure><img src="/files/kRFUjdphWzrLq2WmofN6" alt=""><figcaption></figcaption></figure></div>


---

# Agent Instructions: 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:

```
GET https://doc.wearepatchworks.com/product-documentation/developer-hub/connector-builder/building-your-own-connector/4-endpoints/endpoint-options/pagination/script-pagination.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
