KashuDocs

Pagination

Every list endpoint answers a page at a time, newest first. A page looks like this:

{
  "object": "list",
  "data": [{ "id": "py_...", "object": "payment", "...": "..." }],
  "has_more": true,
  "next_cursor": "..."
}

Page through a list

A list takes two parameters of its own:

When has_more is true, ask for the next page with cursor set to the last page's next_cursor. Send the cursor back unchanged, with the same filters and the same limit. On the last page, has_more is false and next_cursor is null.

This loop reads every succeeded payment:

let cursor = null;
do {
  const page = await kashu("GET", `/v1/payments?status=succeeded&limit=100${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ""}`);
  for (const payment of page.data) console.log(payment.id, payment.amount_captured);
  cursor = page.next_cursor;
} while (cursor);

Start again when a cursor expires

A cursor works for one hour, and only for the list that made it. An older cursor answers 400 cursor_expired, so start the list again. A cursor sent to another list, or with other filters or another limit, answers 400 cursor_invalid.

Filter a list

Lists take filters of their own, such as status on payments or customer on payment methods. The API reference lists each one.