We assume you will have some familiarity with scripting languages in order to use this feature. If you prefer to work without code, Custom Connector also offers a range of standard paging options that will suit most needs. Read Pagination for a description of the available options.
Using Script Paging
When creating a custom connector:- Follow the process given in Custom connector setup.
- When selecting a Pagination option, select Script.
- This gives you a multi-line text input field where you can write your Script Paging script, following the syntax rules given below.
limit and offset parameters:
- The request for data is sent to the endpoint URI, passing all header, query and URI paramters. The script isn’t executed at this point.
- The first page of results is retrieved, based on the passed parameters.
- The script is now executed, sequentially one line at a time. The script can now modify any parameters, including those in the response header and response body which was retrieved in step 2.
- The next page of data is retrieved, based on the parameters which may have been modified by the script.
- The script is executed again.
- Steps 4 and 5 continue until a script operation determines that data retrieval should stop, or the end of the retrievable data is reached.
Basic syntax
Script Paging scripts are composed of statements. Each statement typically performs a single action, such as setting a variable, modifying a request, or processing a response. A script typically consists of multiple statements. Each statement must be placed on a separate line and end with a semicolon;.
You can include comments in your scripts to explain the logic or to temporarily disable code.
- Single-line comments start with
//. - Multi-line comments are enclosed between
/*and*/.
Variables
Variables are defined by the keywordvar followed by the variable name and the value assigned to it. Variables can have one of four data types:
- String: A string of characters, enclosed in quotes
" ". - Boolean:
trueorfalse. - Number: An integer with or without a decimal point.
- Array: An array of strings, booleans, or numbers.
Debug logging
To help debug your pagination scripts, you can add debug logging by using@log(...). The parameters can include strings and any supported types of variable references.
After you add logging, the messages appear in the Logs tab in Custom Connector or the Logging tab in at the debug level.
Some examples of logging:
Example 1
@pager.stop rule not returning true when expected.
Arithmetic operations
Arithmetic operations can be performed directly within variable assignments. For example:String operations
To concatenate strings or string variables, use the+ operator. You can concatenate any number of strings or string variables in a single statement. Some examples:
", they must be escaped with the \ character when assigned to a string variable:
Comparison expressions
Script Paging supports the following comparison operators:- Equal to
== - Not equal to
!= - Less than
< - Less than or equal to
<= - Greater than
> - Greater than or equal to
>=
"value" operator "value". For example:
Script Paging operations
The full power of Script Paging is from the operations that allow you to define how responses from endpoints are processed. These operations are listed in this section. Operation statements begin with the@ symbol. The operation may return data which you can assign to a variable, or it may perform some operation based on the result of an evaluated expression.
pager.pageCount()
Returns the number of pages fetched. You can assign the returned number to a variable for use later in the script. Example:pager.stop(expression)
Tells the connector not to attempt to fetch the next page if theexpression evaluates to true.
Parameters:
- expression: string. A valid Script Paging comparison expression that will be evaluated to produce a
trueorfalseresult.
response.header.get(key)
Returns the value of the specified key in a key-value pair in the response header. Parameters:- key: string. The key that you want the value of.
response.header.getNextLink()
Gets the next page link from the response header of an API that uses link header paging. This works for any API that uses a standard link header paging model, for example the GitHub API illustrated in Example 6. Example:response.header.getLastLink()
Gets the last page link from the response header of an API that uses link header paging. This works for any API that uses a standard link header paging model, for example the GitHub API illustrated in Example 6. Example:response.body.get(key)
Returns the value of the specified key in a key-value pair in the response body. Parameters:- key: string. The key that you want the value of. You must specify the key location using JSON Pointer notation, as defined in RFC 6901.
response.status.get()
Return the value of the response status code as a number. Example:request.header.put(key, value)
Adds the specified key value to the request headers parameters. Parameters:- key: string. The name of the key that the value will be assigned to.
- value: string. The value that will be assigned to the key.
request.header.remove(key)
Removes the value of the specified key from request header parameters. Parameters:- key: string. The name of the key that will be removed.
request.header.clear()
Clears all existing values from the request header parameters. Example:request.header.get(key)
Returns the value of the specified key in a key-value pair in the request header. Parameters:- key: string. The key that you want the value of.
request.query.put(key, value)
Adds the specified key value to the request query parameters. Parameters:- key: string. The name of the key that the value will be assigned to.
- value: string. The value that will be assigned to the key.
request.query.remove(key)
Removes the value of the specified key from request query parameters. Parameters:- key: string. The name of the key that will be removed.
request.query.clear()
Clear all existing values from the request query parameters. Example:request.query.get(key)
Returns the value of the specified key in a key-value pair in the request query parameters. Parameters:- key: string. The key that you want the value of.
request.body.set(jsonString)
Sets the value of a key-value pair in the request body. This is used with JSON body format. Parameters:- jsonString: string. A valid JSON string that contains a key-value pair. You must specify the key location using JSON Pointer notation, as defined in RFC 6901. Quotes in the string must be escaped as
\".
request.body.put(key, value)
Adds a new key-value pair to the request body. This is used with JSON body format. Parameters:- key: string. The name of the key that you want to add.
- value: string. The value assigned to the key.
request.body.remove(key)
Removes the value of the specified key from the request body. This is used with JSON body format. Parameters:- key: string. The name of the key that you want to remove.
request.body.clear()
Clears all existing values from the request body. This is used with JSON body format. Example:request.body.get(key)
Returns the value of the specified key in a key-value pair in the request body. This is used with JSON body format. Parameters:- key: string. The key that you want the value of.
request.uri.set(URI)
Sets the value of the URI. Parameter:- URI: string. The URI to set.
request.uri.append(path)
Appends a string to the request URI. Typically used to append a relative path to a base URI. Parameter:- path: string. The path to append to the request URI.
request.uri.replace(parameter, value)
Replaces parameterized values in the URI path. The parameterized values are set as URI parameters. Parameters:- parameter: string. The name of the parameter to be replaced.
- value: string or number. The value to replace the parameter with.
request.ratelimit.set(allowlist, header, wait, retry)
Configures the rate limit for the endpoint. Suggested values for rate limits can usually be found in the API’s documentation. Parameters:- allowlist: array of numbers, for example
[429, 403]. These are the status codes for surpressing the rate limit error. - header: string. The response header key whose presence indicates throttled response.
- wait: number. Sets the wait in milliseconds, which should be extracted from the response.
- retry: number. Sets number of retries.
JSON manipulation operations
Add a key-value pair to a JSON object.
The updated JSON object value should be assigned to a new variable. Parameters:- key: string. The key to add or update in the form of a JSON pointer.
- value: string. The value to assign.
- jsonObject: string. The JSON object to which the key-value pair will be added.
Remove a key from a JSON object
The updated JSON object value should be assigned to a new variable. Parameters:- key: string. The key to remove in the form of a JSON pointer.
- jsonObject: string. The JSON object from which the key will be removed.
json.get(path, object)
Extracts a value from a JSON object. This requires knowing the path to the object in the JSON structure. Parameters:- path: string. The JSON path to the object. Specify the path using
/to separate the names of nested elements, with/by itself indicating a root-level element. - object: string. The JSON object to extract the value from.
Increment and decrement operations
Increment a value
Increment a number. The incremented value should be assigned to a new variable.Decrement a value
Decrement a number. The decremented value should be assigned to a new variable.Examples
The following examples show some common uses for Script Paging. In each case, we give a real-world API call and the response returned by that call. We then show a suggested script to paginate that response.Example 1: relative path
In this example, each page of data retrieved from the API endpoint provides us with a relative path which points to the next page we need to retrieve. We can use a script to read that path from each page and use it to retrieve the next page. The following URI retrieves filtered data in JSON format:Example 2: full path
This is similar to the last example, in that each page of data contains a pointer to the next page of data. However, the pointer is a full URI, not a relative path. This makes our script simpler, as we don’t have to concatenate the different parts of a URI. Use the following URI to retrieve the first page of data:Example 3: page based
An endpoint which uses page-based pagination requires an incrementing a page parameter to retrieve each subsequent page. Each page of data contains its page number in the response structure, meaning that we need to read that number, increment it, and query again with the incremented page number. In the following URI, we are telling the endpoint to send us data starting at page 1:Example 4: cursor based
Cursor pagination uses a cursor parameter to navigate between pages. We need a script that reads the value of the next page cursor and puts that into the next query. Use the following URI to retrieve a page of data:starting_after. The following script will extract this and put it into the next page query:
Example 5: offset
Offset pagination involves paging by incrementing a query parameter. We need to set the parameter in our initial query, and then use a script to increment the parameter for each subsequent page. Use the following URI to retrieve the first page of data:Example 6: link header
Link header pagination uses a field in the response header to point to the next page, as in the following example:GraphQL paging example
API endpoint:https://organizationapi.com/graphql
The API integrates pagination directly within the query structure. This requires us to parameterize the page value in the GraphQL query and to pass the page value in the variables.
Example query to fetch customers:

