Search the docs

Pages and API endpoints

Developer dashboard
Docs/Working with Many Records

Working with Many Records

Bringing in a customer list, a product catalogue or a year of invoices? Send one request per record, a few at a time, each with its own Idempotency-Key. A dropped connection or a retry can then never create anything twice, and one bad row never stops the rest.

The pattern

  1. Give every record a stable key from your own data (a row number, your own ID): import-2026-11-customers-row-42.
  2. Send it as Idempotency-Key with the create request. Sent again within 24 hours, the same key returns the first answer instead of creating a second record.
  3. Keep 3–5 requests in flight at once, and stay inside your plan's rate limit: on a 429, wait for Retry-After seconds.
  4. Retry network failures and 5xx answers with the same key. Don't retry a 4xx: record it with its code and request_id, fix the row, and send it again.

Example: import customers from a CSV

import-customers.mjs (Node 18+)
const API = "https://api.syncbooksapp.com/api/v1";
const KEY = process.env.SYNCBOOKS_API_KEY;

async function createCustomer(row, attempt = 1) {
  const res = await fetch(`${API}/customers`, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${KEY}`,
      "Content-Type": "application/json",
      "Idempotency-Key": `customers-import-${row.ref}`, // same row → same key, every time
    },
    body: JSON.stringify({ name: row.name, email: row.email, phone: row.phone }),
  }).catch(() => null);

  if (res?.ok) return { ref: row.ref, ok: true, replayed: res.headers.get("Idempotent-Replayed") === "true" };
  const retryable = !res || res.status === 429 || res.status === 409 || res.status >= 500;
  if (retryable && attempt < 5) {
    const wait = Number(res?.headers.get("Retry-After")) || 2 ** attempt;
    await new Promise((r) => setTimeout(r, wait * 1000));
    return createCustomer(row, attempt + 1);
  }
  const body = res ? await res.json().catch(() => ({})) : {};
  return { ref: row.ref, ok: false, code: body.code ?? "network_error", error: body.error, request_id: body.request_id };
}

// A few at a time.
async function importAll(rows, inFlight = 4) {
  const results = [];
  for (let i = 0; i < rows.length; i += inFlight) {
    results.push(...(await Promise.all(rows.slice(i, i + inFlight).map((r) => createCustomer(r)))));
  }
  const failed = results.filter((r) => !r.ok);
  console.log(`${results.length - failed.length} imported, ${failed.length} to fix`);
  console.table(failed);
}

Run it again after fixing the failed rows: rows that already went in come back with Idempotent-Replayed: true and nothing is created twice (keys are kept for 24 hours).

Updating many records

List them page by page (up to 100 a page), then PUT /api/v1/<resource>/:id each one, a few at a time. A PUT sets the fields you send, so sending it twice is harmless and needs no key.

Spreadsheet imports

For a one-off move from another system, people can also import CSV files straight into SyncBooks (Accounting → Data import: customers, vendors, products, opening balances…) without writing code.