Pagination
Many times it is necessary to paginate the results that the server returns in order to retrieve additional older or newer items because the server may not return how many items you want.
Specification
The pagination
collection is placed in the root level of Request Specification, along with url
, method
, body
and response
.
Pagination directives should be placed inside the pagination
collection.
mergeWithParent
Type: Boolean
Default: true
Specifies the condition to merge pagination parameters with the original request parameters or not. The default value is true
, which means that all of your pagination request parameters will be merged with the original request parameters.
If the value is set to false
, then no parameters will be merged, but directly used to make a pagination request.
url
Type: IML string
Specifies the URL that is called when the pagination request is executed. It overrides the original request URL no matter the value of mergeWithParent
.
method
Type: IML string
Specifies the HTTP method to be used when executing the pagination request. It overrides the original request method no matter the value of mergeWithParent
.
headers
Type: IML flat object
Specifies the request headers to be used when executing the pagination request. It merges with headers of the original request, overriding headers with the same name when mergeWithParent
is set to true
(default).
qs
Type: IML flat object
Specifies the request query string parameters to be used when executing the pagination request. It merges with query string parameters of the original request, overriding ones with the same name when mergeWithParent
is set to true
(default).
body
Type: Any IML type
Specifies the request body when the request method is anything but GET
to be used when executing the pagination request. It overrides the original request body no matter the value ofmergeWithParent
.
condition
Type: IML string or Boolean
Specifies whether to execute the pagination request or not. It has all context variables available to it like the response
collection, such as body
, headers
, and temp
. Use this to stop paginating if the server is sending you information about the number of pages or items, or if the next page is available or not.
Limits
As we cannot paginate to infinity, there are four limits on the paginated requests.
Max Request Count
... all requests performed by a single module
100
Max Pagination Request Count
... pagination requests performed by a single module
50
Max Past Record
... paginated records
3200
Max Call Timeout
... seconds
40
Examples
Total pages
The common method of pagination is to use total pages
or pages count
. The service gives information about how many pages of content (the total count) are available and you have to iterate over those pages.
{
"Data": [
{...},
{...},
{...},
{...},
{...}
]
"TotalItems": 42,
"TotalPages": 10
}
Limit - offset
This is another common way to implement pagination. Set the paging cursor using two parameters:
limit
- sets the maximum amount of records being retrieved per pageoffset
- sets the number of skipped records from the beginning of the data set
Use two parameters to control the pagination.
[
{...},
{...},
{...},
{...},
{...}
]
Next page token
The next page token is a unique identifier of a next page that is provided in the response. You can get the next page without counting some pages or offsets using this token only. Sometimes the "Next page URL" is provided instead of only the token, but the flow is quite similar.
{
"data": [
{...},
{...},
{...},
{...},
{...}
],
"nextPageToken": "ABCDEFGHHGFEDCBA"
}
Next page URL
The next page URL is a link to the next page that is provided in the response.
If the next page URL is provided, you can map it directly in the pagination directive.
{
"items": [
{...}, },
{...}
],
"_links": {
"next": {
"href": "https://api.abc.com/locations?page=ZmFsc2V8aHR...."
},
"previous": null
}
}
Has more items
When using this method, you get information on whether the data set contains more records or not.
{
"data": [
{...},
{...},
{...},
{...},
{...}
],
"has_more_items": true
}
Page only
This type of pagination isn't ideal, but many services use this. With this method, you continue to ask for the next page until you get an empty response.
[
{...},
{...},
{...},
{...},
{...}
]
See the article regarding debugging pagination in list and search modules for additional information.
Last updated