Pagination

Pagination helps us restrict the amount of results shown in a specific data set. It will return paging information that will help you navigate through the data


Paginated (Paged) Resource

When pagination data is returned, it is usually returned in the meta attribute of the payload.

  • Name
    meta.current_page
    Required
    Type
    integer
    Description

    Current page of the data set

  • Name
    meta.from
    Required
    Type
    integer
    Description

    The index the data set is from. This is not an ID. For example, if you're on the second page, with a limit of 10 items per page, from will be 11.

  • Name
    meta.to
    Required
    Type
    integer
    Description

    The index the data set is to. This is not an ID. For example, if you're on the second page, with a limit of 10 items per page, to will be 20.

  • Name
    meta.last_page
    Required
    Type
    integer
    Description

    The last page number in the data set. This is calculated using the total number of records divided by the page size.

  • Name
    meta.per_page
    Required
    Type
    integer
    Description

    The number of records to show per page.

  • Name
    meta.total
    Required
    Type
    integer
    Description

    Total number of records found, across all pages.

Paged Pagination Resource

{
  "meta": {
    "current_page": 1,
    "from": 1,
    "last_page": 10,
    "per_page": 2,
    "to": 2,
    "total": 20,
  }
}

Example using pagination

By default, the only pagination we currently support is paged pagination. Paged pagination is less efficient as we need to know how many total records are in the data set, which would involve counting all matching records and working out the number of pages that are required.

The SDK provides an easy way to paginate results on endpoints.

  • Name
    result_mode.mode
    Required
    Type
    string
    Description

    To enable pagination on a data set, this value should always be set to paginated.

  • Name
    result_mode.attributes.page
    Required
    Type
    int
    Description

    The page you want to show results from. This is 1 indexed, so if you want to show the first page of results, use the value 1.

  • Name
    result_mode.attributes.limit
    Required
    Type
    integer
    Description

    The number of results to return per page.

Manual pagination using cURL

    curl \
      --location \
      --request GET https://service.itccompliance.co.uk/data \
      --data-url-encode \
      --data "result_mode[mode]=paginated" \
      --data "result_mode[attributes][page]=1" \
      --data "result_mode[attributes][limit]=2"

Paginated response

{
  "data": [
    {
      "id": "716f30d7-c8dc-4c7d-9f5a-944c8f12d523"
    },
    {
      "id": "e0631eb5-d908-4634-a1a2-c9cce8a18b34"
    },
  ],
  "meta": {
    "current_page": 1,
    "from": 1,
    "last_page": 10,
    "per_page": 2,
    "to": 2,
    "total": 20,
  }
}