TypeScript SDK
npm install @klozeo/sdkRequires Node.js 18+ (or any modern browser). Ships ESM + CJS with full TypeScript types.
Quick start
Section titled “Quick start”import { Klozeo } from "@klozeo/sdk";
const client = new Klozeo("sk_live_your_api_key");
// Create a leadconst resp = await client.leads.create({ name: "Acme Corporation", source: "website", city: "San Francisco", email: "contact@acme.com", rating: 4.5, tags: ["enterprise", "saas"],});console.log(`Created: ${resp.id}`);
// List with filtersimport { city, rating } from "@klozeo/sdk";
const leads = await client.leads.list({ filters: [city().eq("Berlin"), rating().gte(4.0)], sortBy: "rating", sortOrder: "desc", limit: 20,});
// Iterate all pages automaticallyfor await (const lead of client.leads.iterate({ filters: [city().eq("Berlin")],})) { console.log(lead.name);}
// Export to CSVconst csv = await client.leads.export({ format: "csv" });Client options
Section titled “Client options”const client = new Klozeo("sk_live_your_api_key", { baseUrl: "https://custom.api.com", // default: https://api.klozeo.com/api/v1 timeout: 30_000, // ms, default 30 000 maxRetries: 3, // retries on 429 / 5xx});Filters
Section titled “Filters”import { city, country, rating, score, tags, or, attr,} from "@klozeo/sdk";
const leads = await client.leads.list({ filters: [ city().eq("Paris"), or().city().eq("Lyon"), // OR city = Lyon rating().gte(4.0), tags().contains("enterprise"), attr("industry").eq("Software"), // dynamic attribute ],});Attribute helpers
Section titled “Attribute helpers”import { textAttr, numberAttr, boolAttr, listAttr } from "@klozeo/sdk";
await client.leads.create({ name: "Acme", source: "web", attributes: [ textAttr("industry", "Software"), numberAttr("employees", 500), boolAttr("verified", true), listAttr("products", ["CRM", "ERP"]), ],});Error handling
Section titled “Error handling”import { KlozeoError, RateLimitError, AuthError, NotFoundError } from "@klozeo/sdk";
try { const lead = await client.leads.create({ name: "Acme", source: "web" });} catch (err) { if (err instanceof RateLimitError) { console.log(`Rate limited. Retry after ${err.retryAfter}s`); } else if (err instanceof AuthError) { console.log("Invalid or revoked API key"); } else if (err instanceof NotFoundError) { console.log("Lead not found"); } else if (err instanceof KlozeoError) { console.log(`API error ${err.status}: ${err.message}`); }}const note = await client.notes.create(leadId, "Called back — very interested.");const notes = await client.notes.list(leadId);await client.notes.delete(noteId);Batch operations
Section titled “Batch operations”// Create up to 100 leads at onceconst results = await client.leads.batchCreate(leads);
// Delete by IDsawait client.leads.batchDelete(["cl_...", "cl_..."]);Full source and examples: github.com/lbframe/sdk-typescript