Paginating collections

Paginating collections

Prepr returns collections of resources in a wrapper object that contains extra information useful for paginating overall results.

{
    "skip": 0,
    "limit": 2
}

Will result in:

{
    "items": [{...},{...}],
    "total": 98,
    "after": "YWZ0ZXJfMg==",
    "before": "YmVmb3JlXzA=",
    "skip": 0,
    "limit": 2
}

In the above example, a client retrieves the next 100 resources by repeating the same request, changing the skip query parameter to 100. You can use the sort parameter when paging through larger result sets to keep the order predictable. For example, sort=-created_on will order results by the time the resource was created.

Limit

You can specify the maximum number of resources returned as a limit query parameter.

Note: The maximum number of resources returned by the API is 1000. The API will throw a Bad Request for values higher than 1000 and values other than an integer.

The default number of resources returned by the API is 100.

Skip

You can specify an offset with the skip query parameter.

Note: The API will throw a Bad Request for values less than 0 or values other than an integer.

By combining skip and limit you can paginate through results:

Page 1: skip=0, limit=15 Page 2: skip=15, limit=15 Page 3: skip=30, limit=15 etc.

Was this article helpful?

We’d love to learn from your feedback