Conventions
Pagination
A list comes one page at a time. You page with a cursor, not an offset, so a night added halfway through never shifts a row.
How to page
- Ask for the list, optionally with
limit(default 25, at most 100). - Read
meta.next_cursor. When it isnull, you are done. - Otherwise ask for the same list again, with the same filters and
cursoradded, untilnext_cursorisnull.
Never build a cursor yourself and never change one: it is opaque, and a cursor that is not ours gets 400 invalid_request.
The meta of a list
| Name | Type | Default | Description |
|---|---|---|---|
request_id required | string | - | Id of this request. |
count required | integer | - | Number of items in data. |
limit required | integer | - | The page size that was applied. |
next_cursor required | string | null | - | Pass as ?cursor= for the next page. Null on the last page. |
attribution optional | Attribution | - |
Fetching everything
async function all(path, params = {}) {
const out = [];
let cursor = null;
do {
const qs = new URLSearchParams({ ...params, limit: "100", ...(cursor ? { cursor } : {}) });
const res = await fetch(`https://api.partyppl.nl/v1${path}?${qs}`, {
headers: { Authorization: `Bearer ${process.env.PPL_TOKEN}` },
});
if (!res.ok) throw new Error((await res.json()).error.message);
const { data, meta } = await res.json();
out.push(...data);
cursor = meta.next_cursor;
} while (cursor);
return out;
}
const amsterdam = await all("/events", { city: "Amsterdam" });Do not fetch the whole agenda to publish it elsewhere; the terms say so. Filter on what you show and keep what you fetch.
Updated