Follow

Pagination

All endpoints which allow the fetching of multiple results can be paginated. Pagination splits results of a query into multiple "pages" for decreased latency and improved responsiveness in asynchronous workflows. 

If a GET request has been paginated, it will include an additional property next which contains a URL string for the next "page" of results:

{
     'next': 'https://api.payjunctionlabs.com/customers?offset=50',
     'results': [
          ...
     ]
}

In some cases, as with customers, you might want to save the last offset value in order to fetch just the new results since the last query. Otherwise, to get the full results for a query that is paginated, a loop or a recursive function will be needed to retrieve and concatenate the pages. 

Endpoints that utilize pagination also allow for the offset query parameter to be sent to return results beginning from a provided index. As in the example above, the next property specifies offset=50 in the query parameter. This simply tells the API to only return results starting from index 50. If an offset value exceeds the index of records an empty result set is returned. 

Additionally these endpoints will accept a limit query parameter to specify the maximum number of results for a query. For example, this URL:

https://api.payjunctionlabs.com/terminals?offset=5&limit=5

This tells the API to return results starting from index 5 and to only return up to 5 results. If there are further pages of results, the next property will properly set the query parameters to keep the limit set in the original request. In our example above, the next property would be:

https://api.payjunctionlabs.com/terminals?offset=10&limit=5

This allows integrators to control the pagination for their needs. Whenever a result set is returned with prior "pages" available, a prev property will also be returned with the URL to go back to the previous "page" of results:

GET /customers/?offset=25&limit=25
{
    "prev": "https://api.payjunctionlabs.com/customers/?offset=0&limit=25",    
    "next": "https://api.payjunctionlabs.com/customers/?offset=50&limit=25",
    "results": [
        ....
    ],
}
Additional Considerations for Query Parameters
  • The limit parameter cannot exceed 50.
  • If the offset parameter exceeds the index of available resources an empty result set will be returned.