Get started
Pagination
Every list answer has the same shape; long lists are paged with a cursor.
The list shape
GET /domains?limit=2
{
"data": [
{ "name": "demo-domain-2.com", "status": "active" },
{ "name": "demo-domain-1.com", "status": "active" }
],
"has_more": true,
"next_cursor": "WyJkb21haW5zIiwiZGVtby1kb21haW4tMS5jb20iXQ"
}| Query | Meaning |
|---|---|
limit | Items per page, 1 to 100. Default 25. |
cursor | The next_ of the page before. Leave it out for the first page. |
| Filters | Per endpoint, e.g. status or domain. Listed on each endpoint's page. |
Each endpoint's page says how its list is sorted. When has_ is false, next_ is null and you have everything. Not paged (everything in one answer, no has_ / next_): GET /workspaces, GET /prewarmed-inventory and POST /domains/availability. GET /masking-domains pages 200 at a time (no limit).
Read every page
Node.js
async function listAll(path) {
const items = [];
let cursor = null;
do {
const url = new URL(`https://api.scaledmail.com/v2${path}`);
url.searchParams.set("limit", "100");
if (cursor) url.searchParams.set("cursor", cursor);
const res = await fetch(url, {
headers: {
Authorization: `Bearer ${process.env.SCALEDMAIL_API_KEY}`,
"Workspace": "org_DemoWorkspace1",
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const page = await res.json();
items.push(...page.data);
cursor = page.next_cursor;
} while (cursor);
return items;
}Rules
- Send the same filters with every page. A cursor from another list, or one that was changed, answers
400invalid_.cursor - Treat cursors as opaque. Don't build or change them.
- Objects created after your first page may not show on later pages. Start again from the first page to catch new ones.
