Pagination
In this guide, we will look at how to work with paginated responses when querying the Unlocktopus API. By default, all responses limit results to thirty. However, you can go as high as 100 by adding a limit parameter to your requests.
When an API response returns a list of objects, no matter the amount, pagination is supported. In paginated responses, objects are nested in a data attribute and the response contains metadata about the pagination, such as the total count of items and whether there are more items to fetch.
The first page has the number 0 and the last page has the number totalPages - 1. The hasPrevPage and hasNextPage attributes indicate whether there is a previous or next page. The prevPage and nextPage attributes contain the number of the previous and next page, respectively.
Example fetching licenses
In this example, we request a list of licenses belonging to a product. As a result, we get a list of 10 licenses and can tell by the hasNextPage attribute that we can fetch the next page.
Request attributes
- limit
limit- Type
- integer
- Description
Limit the number of items returned.
- page
page- Type
- integer
- Description
The number of the page to fetch.
Response attributes
- data
data- Type
- array
- Description
An array of objects.
- totalCount
totalCount- Type
- integer
- Description
The total number of items matching the filter.
- page
page- Type
- integer
- Description
The number of the page being fetched.
- limit
limit- Type
- integer
- Description
The number of items per page.
- totalPages
totalPages- Type
- integer
- Description
The total number of pages.
- hasPrevPage
hasPrevPage- Type
- boolean
- Description
Whether there is a previous page.
- hasNextPage
hasNextPage- Type
- boolean
- Description
Whether there is a next page.
- prevPage
prevPage- Type
- integer
- Description
The number of the previous page.
- nextPage
nextPage- Type
- integer
- Description
The number of the next page.
Manual pagination
curl -G https://api.unlocktopus.com/v0/licenses \
-H "Authorization: Bearer {token}" \
-d starting_after="s4WycXedwhQrEFuM" \
-d limit=10
Paginated response
{
"data": [
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"productId": "e138d6ce-fdee-4fc1-8356-ad166ef47f27",
// ...
},
// ...
],
"totalCount": 50,
"page": 2,
"limit": 10,
"totalPages": 5,
"hasPrevPage": true,
"hasNextPage": true,
"prevPage": 1,
"nextPage": 3
}