Paging

List endpoints typically require paging. Please adhere to the paging headers when fetching lists.

Headers

Page information is provided via the X-Next-Page HTTP header.

If a response includes this header then the response body does not contain all of the data in the list or query.

The header provides a full URL to GET from to obtain the next page. This URL will have all required context to continue the list or query.

Example

This basic example demonstrates using the X-Next-Page header with fetch.

async function getOrgs(accessToken) {
  let orgs = [];
  let nextUrlPath = "/organizations";

  do {
    const url = new URL(nextUrlPath, "https://api.loke.global");
    const response = await fetch(url, {
      headers: {
        "Authorization": "Bearer " + accessToken,
      }
    });

    if (!response.ok) {
      throw new Error("Network response was not OK");
    }

    orgs.push(await response.json());
    nextUrlPath = response.headers.get("X-Next-Page");
  } while (nextUrlPath); // nextUrlPath will be null if there are no more pages

  return orgs;
}

In this article