Pagination

In this guide, we will look at how to work with paginated responses when querying the Previsto API. By default, all responses limit results to twenty. However, you can go as high as 1000 by adding a size parameter to your requests.

When an API response returns a list of objects, no matter the amount, pagination is supported. In paginated responses, an x-total-count header is added to the response with the total amount of objects available. You can use the page query parameter to browse pages.

Example using page

In this example, we request the second page. As a result, we get a list of three contacts and by comparing page*size with the header x-total-count we can tell that we have reached the end of the resultset.

  • Name
    page
    Type
    string
    Description

    The zero-based page you want to fetch.

  • Name
    size
    Type
    integer
    Description

    Limit the number of items returned. (default 20)

Manual pagination using cURL

curl -G https://api.previsto.io/contacts \
  -u sk_12345 \
  -d page=1 \
  -d size=10

Paginated response

[   
  {
    "id": "cont-WAz8eIbvDR60rouK",
    // ...
  },
  {
    "id": "cont-hSIhXBhNe8X1d8Et"
    // ...
  },
  {
    "id": "cont-fbwYwpi9C2ybt6Yb"
    // ...
  }
]