SDK examples
Pagination, idempotent writes, error handling, OAuth token refresh and the starter project.
Every record, page after page
TypeScript
for await (const contact of hevia.contacts.listAll({ limit: 100, updated_since: "2026-11-01T00:00:00Z" })) {
console.log(contact.email);
}
const firstHundred = await hevia.deals.listAll().toArray({ max: 100 }); // stops fetching earlyA write that survives restarts
TypeScript
await hevia.deals.create({ title: "Order 42", value_cents: 12900 }, { idempotencyKey: "order-42" });Handle a missing scope
TypeScript
import { PermissionError } from "@hevia/sdk";
try {
await hevia.deals.create({ title: "Website relaunch", value_cents: 480000 });
} catch (error) {
if (error instanceof PermissionError && error.code === "insufficient_scope") {
// ask the owner for deals:write
} else throw error;
}OAuth with automatic refresh
TypeScript
import { HeviaClient, OAuthTokenManager } from "@hevia/sdk";
const manager = new OAuthTokenManager({ clientId, tokens, onTokens: (t) => saveToDatabase(t) });
const hevia = new HeviaClient({ tokenProvider: manager.tokenProvider });The manager refreshes about 60 seconds before expiry, shares one refresh between concurrent calls and hands you the rotated refresh token.
Rate limit of the last call
TypeScript
await hevia.tasks.list({ open: true });
console.log(hevia.rateLimit); // { limit, remaining, reset }Starter project
Shell
npm run create-app -w @hevia/sdk -- ../my-integrationCopies examples/create-hevia-app: a webhook receiver with signature check and a contacts listing.