Pagination

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

When an API response returns a list of objects, no matter the amount, cursor pagination is supported. In paginated responses, objects are nested in a data attribute, and the pagination attributes (below) are at the same level.

Pagination attributes

  • Name
    path
    Type
    string
    Description

    The URL of the current request.

  • Name
    per_page
    Type
    integer
    Description

    The number of items requested to be returned per page.

  • Name
    next_cursor
    Type
    string|null
    Description

    The cursor to use to page forward in the resultset.
    When null, there are no more pages.

  • Name
    next_page_url
    Type
    string|null
    Description

    The URL of the next page in the resultset, including the next_cursor as the cursor value.

  • Name
    prev_cursor
    Type
    string|null
    Description

    The cursor to use to page backward in the resultset.
    When null, there are no more previous pages.

  • Name
    prev_page_url
    Type
    string|null
    Description

    The URL of the previous page in the resultset, including the prev_cursor as the cursor value.

Example using cursors

In this example, we are paginating over a list of 100 buildings in chunks of 50.

Manual pagination using cURL

curl -G https://app.wunderite.com/api/v1/risks/{risk}/data/buildings \
  -H "Authorization: Bearer {token}" \
  -H "Accept: application/json" \
  -d per_page=50

First paginated response

{
  "data": [
    {
      "object": "building",
      "uuid": "8f2c9f0a-cd6a-4ea7-9ed3-b5d013d01c5b",
      // ...
    },
    {
      "object": "building",
      "uuid": "8d2c9f0a-cd6a-4ea7-9ed3-b5d013d01c3b",
      // ...
    },
    {
      "object": "building",
      "uuid": "8e2c9f0a-cd6a-4ea7-9ed3-b5d013d01c1b",
      // ...
    },
    // ... and 47 more building objects
  ],
  "path": "https://app.wunderite.com/api/v1/risks/{risk}/data/buildings",
  "per_page": 50,
  "next_cursor": "eyJpZCI6Ijg2ZjJjOWYwYS1jZDZhLTRlYTctOWVkMy1iNWQwMTNkMDFjNWIiLCJ0aW1lIjoxNjMwNzQwNzIwMDAwfQ==",
  "next_page_url": "https://app.wunderite.com/api/v1/risks/{risk}/data/buildings?cursor=eyJpZCI6Ijg2ZjJjOWYwYS1jZDZhLTRlYTctOWVkMy1iNWQwMTNkMDFjNWIiLCJ0aW1lIjoxNjMwNzQwNzIwMDAwfQ==&per_page=50",
  "prev_cursor": null,
  "prev_page_url": null
}

Second page request

curl -G https://app.wunderite.com/api/v1/risks/{risk}/data/buildings \
  -H "Authorization: Bearer {token}" \
  -H "Accept: application/json" \
  -d cursor=eyJpZCI6Ijg2ZjJjOWYwYS1jZDZhLTRlYTctOWVkMy1iNWQwMTNkMDFjNWIiLCJ0aW1lIjoxNjMwNzQwNzIwMDAwfQ== \
  -d per_page=50

Second paginated response

{
  "data": [
    {
      "object": "building",
      "uuid": "8e2c9f0a-cd6a-4ea7-9ed3-b5d013d01c5b",
      // ...
    },
    {
      "object": "building",
      "uuid": "8e2c9f0a-cd6a-4ea7-9ed3-b5d013d01c3b",
      // ...
    },
    {
      "object": "building",
      "uuid": "8d2c9f0a-cd6a-4ea7-9ed3-b5d013d01c1b",
      // ...
    },
    // ... and 47 more building objects
  ],
  "path": "https://app.wunderite.com/api/v1/risks/{risk}/data/buildings",
  "per_page": 50,
  "next_cursor": null,
  "next_page_url": null,
  "prev_cursor": "eyJpZCI6Ijg2ZjJjOWYwYS1jZDZhLTRlYYYYOWVkMy1iNWQwMTNkMDFjNWIiLCJ0aW1lIjoxBBBwNzQwNzIwMDAwfQ==",
  "prev_page_url": "https://app.wunderite.com/api/v1/risks/{risk}/data/buildings?cursor=eyJpZCI6Ijg2ZjJjOWYwYS1jZDZhLTRlYYYYOWVkMy1iNWQwMTNkMDFjNWIiLCJ0aW1lIjoxBBBwNzQwNzIwMDAwfQ==&per_page=50"
}