Skip to content

Pagination

An endpoint that lists records answers with a list object, one page at a time:

{
"object": "list",
"data": [
{"id": "0199a7c2-4e1b-7f38-b9d2-5a6c8e0f1d73", "object": "customer"}
],
"has_more": true,
"next_cursor": "g3QAAAABZAACaWRtAAAAJDAxOTlhN2MyLTRlMWItN2YzOC1iOWQyLTVhNmM4ZTBmMWQ3Mw"
}
  • data holds the page’s records.
  • has_more says whether another page follows.
  • next_cursor is what to send as cursor to read the next page, and null on the last.
  • total_count, how many records match across every page, is there only when the request asked for it.

A list takes these inputs, in the query string of a GET and in the body of a search:

  • limit: how many records a page holds, from 1 to 100. The default is 20.
  • cursor: the next_cursor of the page before.
  • include_total_count: true to add total_count. It is answered on the first page only, and refused beside a cursor, since it is the same number on every page; keep the first page’s.

To read every page, send each page’s next_cursor back until has_more is false:

const customers = []
let cursor = null
do {
const response = await fetch("https://api.summerbase.com/v1/customers/search", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.SUMMERBASE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify(cursor ? { limit: 100, cursor } : { limit: 100 }),
})
const page = await response.json()
customers.push(...page.data)
cursor = page.has_more ? page.next_cursor : null
} while (cursor)