Pagination

In this guide, we will look at how to work with paginated responses when querying the CityPay API. By default, results are set to 20. However, each service defines limits such as 250 by adding a max_results 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 style attribute and have a next_token attribute that indicates whether you there is more data to be returned. Simply if there is a token produced, more data exists.

In this example, we request the page that starts after the conversation with id s4WycXedwhQrEFuM. As a result, we get a list of three conversations and can tell by the has_more attribute that we have reached the end of the resultset.

    Attributes

Manual pagination using cURL

  GET {{host}}/v6/report/client?date_from=2022-01-01&date_until=2024-01-02&max_result=50&next_token=
  -H "cp-api-key: {{api-key}}"

Paginated response

{
  "next_token": "8eIbvDR60rouK...",
  "data": [
    {
      "id": "1234",
      // ...
    },
    {
      "id": "2345",
      // ...
    },
    {
      "id": "3456",
      // ...
    }
  ]
}