Pagination

API endpoints that can return large numbers of objects return their results using an offset-based paging mechanism to improve performance. Applications are able to specify limit and offset query parameters to control what subset of the results are returned to them.

  • The limit parameter sets a maximum number of results to return per call.
  • The limit parameter defaults to a value of 25
  • The limit parameter has a maximum value of 200
  • The offset parameter defines the number of resources in the collection to skip before assembling the results array
  • The offset parameter defaults to 0

To fetch the first set of entries, call the endpoint with offset = 0 and limit = <your-limit>. To fetch the next set of entries, call the endpoint with offset = <previous-offset> + <previous-limit>. Note that you should increment the offset by the limit that is returned in the response object, not by the limit you passed in the query parameter or size of the results array. If <previous-offset> + <previous-limit> >= total, then you have retrieved all of the entries and there are no more to fetch. Note that the total may change between API calls, so always use the most recent values.

A sample request

For an application displaying an organization's workspaces 10 records at a time, the query for page 2 would look like:

/api/organizations/1/workspaces?offset=10&limit=10

Endpoints that support paging return the requested data as well as additional information related to paging:

  • the set of results
  • the offset specified in the query
  • the limit specified in the query
  • the size of the result set returned by the query
  • the total number of resources available in the collection
  • a paging object containing prepared queries for your convenience:
    • the self URL reflects the request that generated this response
    • the next URL can be used to request the next page of results
    • the prev URL can be used to request the previous page of results

A sample response

{
 "workspaces": [    // the results array
   {
     "id": "4Nkidyp3CpUQaotRx1gE",
     "name": "Workspace 1",
     ...
   },
   {
     "id": "EUYYqLMUzLp5vww_z-mf",
     "name": "Workspace 2",
     ...
   },
   ...
 ],
 "limit": 10,        // the query requested a maximum of 10 results
 "offset": 10,       // the query requested to skip the first 10 workspaces (page 1)
 "size": 10,         // the number of results returned for this query
 "total": 50,        // the number of workspaces available in the organization
 "paging": {

   // request URL for the previous page
   "prev": "/api/organizations/1/workspaces?offset=0&limit=10",

   // request URL for the current page
   "self": "/api/organizations/1/workspaces?offset=10&limit=10",

   // request URL for the next page
   "next": "/api/organizations/1/workspaces?offset=20&limit=10",
 }
}