Paging
Lists that can grow long — time entries, members, clients, tags, tasks, approvals, time off, expenses, invoices — come a page at a time.
How it works
- Ask for the list, optionally with
limit(how many rows a page; usually 50 by default, at most 500). - The answer has the rows and a
nextCursor. - While
nextCursorisn'tnull, ask again with the same filters andcursor=set to it. nextCursor: nullmeans you have everything.
bash
curl "https://api.punchly.work/v1/workspaces/$WID/members?limit=200" \
-H "X-Api-Key: $PUNCHLY_API_KEY"json
{
"items": [{ "id": "01928f3e-…", "name": "Amy Patel", "email": "amy@example.com", "role": "member", "status": "active" }],
"nextCursor": "eyJrIjoiUGF0ZWwiLCJpZCI6IjAxOTI4ZjNlLeKApiJ9"
}bash
curl "https://api.punchly.work/v1/workspaces/$WID/members?limit=200&cursor=eyJrIjoiUGF0ZWwiLCJpZCI6IjAxOTI4ZjNlLeKApiJ9" \
-H "X-Api-Key: $PUNCHLY_API_KEY"The rules
- A cursor is opaque. Pass it back exactly as you got it; don't build or change one. Its format may change.
- Keep the filters. A cursor continues the list you asked for. Changing
from,memberIdor another filter mid-way gives you a different list; start again from the first page instead. - Nothing skipped, nothing twice. A cursor marks a place in the sort order, not a page number, so rows added or removed while you read don't shift the rest of the list.
- A cursor that can't be read is refused with
422 VALIDATION, never answered with the first page again, so a mistake can't quietly import the same rows twice.
Reading everything
js
async function all(path) {
const rows = [];
let cursor = null;
do {
const url = new URL(`https://api.punchly.work/v1${path}`);
url.searchParams.set('limit', '500');
if (cursor) url.searchParams.set('cursor', cursor);
const res = await fetch(url, { headers: { 'X-Api-Key': process.env.PUNCHLY_API_KEY } });
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const page = await res.json();
rows.push(...page.items);
cursor = page.nextCursor;
} while (cursor);
return rows;
}Time entries: pages of days
The time-entry list is grouped by day, newest first, so its rows are in days[].entries rather than items. limit counts entries.
- A busy day can continue on the next page: the same
datethen appears at the end of one page and the start of the next. Join them bydate. days[].totalSecondsis the whole day's total, whichever page you're on, so you don't need every page to know a day's total.
js
const byDate = new Map();
for (const day of page.days) {
const seen = byDate.get(day.date);
if (seen) seen.entries.push(...day.entries);
else byDate.set(day.date, day);
}For a pay period or a month across the whole team, use the flat search (every person's entries in one list) or the reports (totals, already summed).