Pagination

In this guide, we will look at how to work with paginated responses when querying the Zamp API.

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 have a nextCursor attribute that you can use to load the next page. When there are no more pages the nextCursor is null.

By default, all responses limit results to 10. However, you can go as high as 100 by adding a limit parameter to your JSON request.

Example using cursors

In this example, we first request all transactions with a limit of 3. As a result, we get back a list of three transactions and can tell by the nextCursor attribute that there are additional pages.

The second request passes the nextCursor value from the first response via the cursor query param. We then get back the second response with two additional transactions. And since the nextCursor is null there are no additional pages.

Query params

  • Name
    limit
    Type
    integer between 1–100 (optional, default=10)

    Limit the number of items returned.

  • Name
    cursor
    Type
    string (optional)

    Cursor returned from a previous response (nextCursor) that's used to load the next page. A null value indicates no more pages.

Request

curl -G https://api.zamp.com/transactions \
  -H "Authorization: Bearer {token}" \
  -d limit=3

Response: first page

{
  "nextCursor": "x4WycXedwhQrEFuM",
  "data": [
    {
      "id": "WAz8eIbvDR60rouK",
      // ...
    },
    {
      "id": "hSIhXBhNe8X1d8Et"
      // ...
    },
    {
      "id": "fbwYwpi9C2ybt6Yb"
      // ...
    }
  ]
}

Request: with cursor

curl -G https://api.zamp.com/transactions \
  -H "Authorization: Bearer {token}" \
  -d limit=3 \
  -d cursor=x4WycXedwhQrEFuM

Response: last page

{
  "nextCursor": null,
  "data": [
    {
      "id": "SIuAFUNKdSYHZF2w",
      // ...
    },
    {
      "id": "l7cGNIBKZiNJ6wqF"
      // ...
    }
  ]
}

Was this page helpful?