This example uses Node's built-in fetch. It prints a count rather than logging customer records. Use a dedicated integration key and keep it on your server.
Follow each page#
const apiKey = process.env.ZELIO_API_KEY;
const workspace = process.env.ZELIO_WORKSPACE;
if (!apiKey || !workspace) {
throw new Error("Set ZELIO_API_KEY and ZELIO_WORKSPACE");
}
const maxPages = 10;
let pagesRead = 0;
let nextToken;
let count = 0;
const seenTokens = new Set();
do {
if (pagesRead >= maxPages) {
// Save nextToken privately with this exact query before resuming.
throw new Error("Page budget reached; this traversal is incomplete.");
}
pagesRead += 1;
const url = new URL("https://zelio-api.zelikore.com/v1/business/customers");
url.searchParams.set("workspace", workspace);
url.searchParams.set("limit", "100");
if (nextToken) url.searchParams.set("nextToken", nextToken);
const response = await fetch(url, {
headers: { "x-api-key": apiKey },
signal: AbortSignal.timeout(30000),
});
if (!response.ok) {
// Let your job scheduler retry reads with bounded backoff.
// Honor Retry-After when response.status is 429.
throw new Error(`Zelikore returned HTTP ${response.status}`);
}
const page = await response.json();
for (const customer of page.items) {
// Upsert into your system using workspace + customer.customerId.
// Store only the fields your integration needs.
count += 1;
}
nextToken = page.nextToken;
if (nextToken) {
if (seenTokens.has(nextToken)) {
throw new Error("Repeated continuation token; stop this traversal");
}
seenTokens.add(nextToken);
}
} while (nextToken);
console.log(`Read ${count} customers`);This run makes at most ten page requests. Set maxPages to a finite budget
appropriate for your job. Reaching the budget is an incomplete traversal; the
example throws instead of reporting its partial count as a completed sync.
Before continuing in another bounded run, save the current nextToken in a
private job checkpoint with the same workspace, page limit, and filters. Do not
log continuation tokens or treat a partial run as a complete customer list.
Make the destination safe to retry#
Upsert records using a stable pair: workspace ID and customer ID. If the job restarts, processing a page twice should not create duplicate destination records.
Do not treat absence from one traversal as proof that a customer was deleted. Customer data can change while you are paging. Apply your destination's deletion policy deliberately.
Extend the integration#
Use get customer when you need resolved contacts and addresses. Use customer summaries when you already have a bounded set of IDs. Use service history to read a customer's service documents and follow-ups. Use generate statement to start an asynchronous statement run, then poll statement status until it reaches a terminal state.
Sync work items#
Work-item traversal follows the same page loop but returns results instead of items. Set activeOnly=true to exclude terminal work; keep that filter unchanged while following nextToken.
Upsert by workspace plus work-item ID, and use search when you need a bounded text query instead of a full traversal.
A created work item can still have a running process; read its process context before reporting completion.
Sync purchase orders and receipts#
List purchase orders with vendorId and status filters, then read receipts per order or across the workspace.
Receipts record what arrived; returns record what went back.
Keep all three keyed by their IDs: purchase-order ID, receipt ID, and return ID.