Skip to content

Pagination

List endpoints return newest-first pages with an opaque cursor. Cursors are stable under concurrent inserts.

List shape

GET https://hub.heka.care/api/platform/v1/invoices?status=open&limit=50

{
  "data": [ { "id": "…", "number": "HSL-2026-00412", … }, … ],
  "has_more": true,
  "next_cursor": "MjAyNi0xMS0yNVQwODozMDowMC4wMDBafDk0…"
}

Pass next_cursor back as cursor to get the next page. limit is 1–100 (default 25). Keep the same filters while you page.

Fetching every page

async function* listAll(path: string, params: Record<string, string> = {}) {
  let cursor: string | null = null
  do {
    const qs = new URLSearchParams({ ...params, limit: '100', ...(cursor ? { cursor } : {}) })
    const res = await fetch(`https://hub.heka.care/api/platform/v1${path}?${qs}`, {
      headers: { Authorization: `Bearer ${process.env.HSL_API_KEY}` },
    })
    if (!res.ok) throw new Error(`HTTP ${res.status}`)
    const page = await res.json()
    yield* page.data
    cursor = page.next_cursor
  } while (cursor)
}

for await (const inv of listAll('/invoices', { status: 'open' })) {
  console.log(inv.number, inv.amount_due)
}

Notes

  • Treat cursors as opaque strings. A malformed cursor returns 400 invalid_cursor.
  • GET /payments is window-based rather than cursor-based: use from and to (ISO-8601) and shrink the window when has_more is true.
  • The catalogue endpoints (/plans, /addons) are small and always return everything.