# Script pagination

## Overview

If a standard pagination type can't meet your pagination requirements, you can create a [custom script](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/pagination-scripts) 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](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts) 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](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables), [meta-variables](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/metadata-variables), and [payload variables](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/payload-variables).

{% hint style="info" %}
For more information about developing pagination scripts, please see our [pagination scripts](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/pagination-scripts) 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FlycIuCpVdBLk3KLdFQn5%2Flimit%20offset%20example%20a1.png?alt=media&#x26;token=ed2edd77-680b-4752-93b4-47d4199ea70a" 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](https://doc.wearepatchworks.com/product-documentation/developer-hub/connector-builder/building-your-own-connector/4-endpoints/url#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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FQYm1mZjj06xdMitLWQB2%2Fadd%20script%20pagination%201.png?alt=media&#x26;token=a11b0f6f-3860-40f0-bb10-2d290da7c9dc" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FMxHBnVLk6lZoGRG3KIR3%2Fadd%20script%20pagination%202.png?alt=media&#x26;token=04b7d578-e0d8-46fa-bee1-d9f7b9299d2d" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FbfvStunQplZs70udbETX%2Fadd%20script%20pagination%203.png?alt=media&#x26;token=802f0eaf-73c5-4adf-92ba-4b2a430ec6ac" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FK26ezCLK8pDulvbQ1A6C%2Fadd%20script%20pagination%204.png?alt=media&#x26;token=8db2cbcf-47bc-4891-aa25-f79f327a654f" alt=""><figcaption></figcaption></figure></div>
