Skip to content

Pagination

Read long lists a page at a time with limit, offset and nextOffset.

List meals and Search foods return one page at a time.

Parameter Type Description
limit integer How many to return, from 1 to 100. Meals default to 20, foods to 30.
offset integer How many to skip. Defaults to 0.

Each page comes with nextOffset beside the list. Send it as offset to read the next page; it is null on the last one.

let offset = 0;
const meals = [];
do {
const response = await fetch(`https://app.splot.health/v1/meals?limit=100&offset=${offset}`, {
headers: { Authorization: `Bearer ${process.env.SPLOT_API_KEY}` },
});
const page = await response.json();
meals.push(...page.meals);
offset = page.nextOffset;
} while (offset !== null);

Pages follow the order of the list, so a meal logged while you read can shift later pages by one. Narrow the list with a date range when you need an exact set.

Last updated