Pagination scripts
Introduction
If a standard pagination type can't meet your pagination requirements, you can create a custom script and apply this as the pagination method for endpoints.
Elements of a pagination script
Pagination scripts typically include:
Inputs
Expected inputs must be inside the payload
key of the data
array. These are summarised below:
Request
An array/object representing the request parts for the current page:
body
A string version of the body.
$returnPayload['body'] = $payload['request']['body'];
headers
An array/object containing a key/value map of request headers.
$returnPayload['headers'] = $payload['request']['headers'];
method
The HTTP method.
$returnPayload = [ 'has_next_page' => false, 'method' => 'GET' ];
url
The entire URL used in the request.
$returnPayload['url'] = $nextPage;
Response
An array/object containing the response parts returned from the request:
headers
An array/object containing a key/value map or response headers.
$links = $payload['response']['headers']['link'][0];
status_code
The HTTP response code.
Payload
The content saved as the payload. For example:
$payload = json_decode($data['payload'], true);
Outputs
If has_next_page
is true, a JSON-encoded array/object should be returned (within the payload
field) with the following:
has_next_page
Whether or not there is another page to be fetched.
$returnPayload['has_next_page'] = true;
url
The URL to use for the next page request.
$returnPayload['url'] = $nextPage;
headers
The headers to use for the next page request.
$returnPayload['headers'] = $payload['request']['headers'];
method
The HTTP method to use for the next page request.
$returnPayload['method'] = $payload['request']['method'];
body
The body content to use in the next request.
$returnPayload['body'] = $payload['request']['body'];
Pagination script example
The sample script below demonstrates link header
functionality.
Last updated