The Moonbase API uses cursor-based pagination for list endpoints that return multiple items. These endpoints return one page of results per API call. Each page contains up to 20 results by default.
Response structure
The API returns items in the data property of the response. Refer to the individual endpoints for the ordering of items since they vary based on the endpoint.
Example: First page (with more results)
{
"type": "list",
"data": [
{
"id": "1CLJt2ub4MavjpDF6NV14F",
"type": "item",
"values": {
"name": {"type": "value/text/single_line", "data": "OrbGrid"},
"updated_at": {"type": "value/datetime", "data": "2025-02-17T16:00:00.000Z"}
}
},
{
"id": "1CLJt2ub4MavjpDF6NV14G",
"type": "item",
"values": {
"name": {"type": "value/text/single_line", "data": "TechStart Inc"},
"updated_at": {"type": "value/datetime", "data": "2025-02-17T16:00:00.000Z"}
}
},
{
"id": "1CLJt2ub4MavjpDF6NV14H",
"type": "item",
"values": {
"name": {"type": "value/text/single_line", "data": "Global Systems"},
"updated_at": {"type": "value/datetime", "data": "2025-02-17T16:00:00.000Z"}
}
}
...
],
"meta": {
"cursors": {
"next": "eyJpZCI6IjFDUDY0dkc2SkhuSkhLUEpLTDVpblcifQ"
}
}
}
Example: Middle page (both prev and next)
{
"type": "list",
"data": [ /* items omitted for brevity */ ]
"meta": {
"cursors": {
"prev": "eyJpZCI6IjFDUzY4Ykp0Z3k5ZGFzOGFzYTg3bmV3OTJuMHE4a2w4MWpBIn0",
"next": "eyJpZCI6IjFDUDY0dkc2SkhuSkhLUEpLTDVpblcifQ"
}
}
}
The next cursor will not be present if there are no more pages to fetch. prev cursor appears when previous pages exist. Enables bidirectional navigation.
Do not pass both before and after in the same request. Cursors are opaque strings—do not parse or modify them—and should be URL-encoded when used in query parameters.
Control pagination using these query parameters:
limit: (Integer) — Maximum number of items to return per page. Must be between 1 and 100. Defaults to 20 if not specified.
after: (String) — Returns results starting immediately after the item identified by this cursor. Use the next cursor from a previous response to fetch the next page.
before: (String) — Returns results starting immediately before the item identified by this cursor. Use the prev cursor from a previous response to fetch the previous page.
Cursors do not expire and remain valid indefinitely. Using an invalid cursor will return a 400 Bad Request error.
Navigating pages
Moonbase SDKs provide methods to automatically iterate through all items across all pages:
async function fetchAllItems(params) {
const allItems = [];
// Automatically fetches more pages as needed.
for await (const item of moonbase.collections.items.list('people', { limit: 5 })) {
allItems.push(item);
}
return allItems;
}
Single page requests
Request one page at a time:
let page = await moonbase.collections.items.list('people', { limit: 5 });
for (const item of page.data) {
console.log(item);
}
// Convenience methods are provided for manually paginating:
while (page.hasNextPage()) {
page = await page.getNextPage();
// ...
}
Make an initial API call to list items
curl https://api.moonbase.ai/v0/collections/organizations/items \
--header 'Authorization: Bearer <token>'
For authentication details, see the Moonbase authentication guide.Check for pagination cursors in the response
- If
meta.cursors.next is missing, all items have been retrieved
- If the
next cursor is present, use it with the after parameter to fetch the next page
- If the
prev cursor is present, use it with the before parameter to fetch the previous page
Fetch next page: curl https://api.moonbase.ai/v0/collections/organizations/items?after=eyJpZCI6IjFDUDY0dkc2SkhuSkhLUEpLTDVpblcifQ \
--header 'Authorization: Bearer <token>'
Fetch previous page: curl https://api.moonbase.ai/v0/collections/organizations/items?before=eyJpZCI6IjFDUDY0dkc2SkhuSkhLUEpLTDVpblcifQ \
--header 'Authorization: Bearer <token>'
Repeat until all required data is processed
Continue using the cursors from each response to navigate forward or backward through results.