Pagination
Every list returns its items a page at a time, with a cursor that opens the next page.
Every list takes two query parameters:
limit: how many items the page holds. Each list’s page in the API reference shows its default and its maximum.cursor: where the page starts. Leave it out for the first page.
It answers with the page’s items in data, and in next_cursor the cursor of the next page, null on the last one:
{
"data": [],
"next_cursor": null
}
To read a whole list, pass each next_cursor back as cursor until it is null:
let cursor = null;
do {
const url = new URL("/v1/sensor-types", "https://api.helementa.com");
if (cursor) url.searchParams.set("cursor", cursor);
const response = await fetch(url, {
headers: { Authorization: `Bearer ${process.env.HELEMENTA_API_KEY}` },
});
const page = await response.json();
// Use page.data here.
cursor = page.next_cursor;
} while (cursor);
A cursor is opaque: pass it back as the list returned it. One the list did not return answers 422 with the code invalid-cursor.