Developers
Menu

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

  1. Ask for the list, optionally with limit (how many rows a page; usually 50 by default, at most 500).
  2. The answer has the rows and a nextCursor.
  3. While nextCursor isn't null, ask again with the same filters and cursor= set to it.
  4. nextCursor: null means 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

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.

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).