Developer

Node.js

fetch, no dependencies.

javascript
const BASE = "https://api.trabalance.com/api/v1";
const KEY = process.env.TRABALANCE_API_KEY;

async function tb(method, path, body) {
const res = await fetch(BASE + path, {
  method,
  headers: {
    Authorization: `Bearer ${KEY}`,
    "Content-Type": "application/json",
    ...(method !== "GET" ? { "Idempotency-Key": crypto.randomUUID() } : {}),
  },
  body: body ? JSON.stringify(body) : undefined,
});
const json = await res.json();
if (!res.ok) throw new Error(`${json.error}: ${json.error_description}`);
return json.data;
}

const { items } = await tb("GET", "/customers?page_size=10");
const customer = await tb("POST", "/customers", { name: "Acme Corp", email: "[email protected]" });
const invoice = await tb("POST", "/invoices", {
receiver: customer.id, date: "2026-08-26",
items: [{ id: "<item id>", qty: 2, rate: 150 }],
});