Skip to content

TypeScript SDK

Terminal window
npm install @klozeo/sdk

Requires Node.js 18+ (or any modern browser). Ships ESM + CJS with full TypeScript types.

import { Klozeo } from "@klozeo/sdk";
const client = new Klozeo("sk_live_your_api_key");
// Create a lead
const 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 filters
import { 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 automatically
for await (const lead of client.leads.iterate({
filters: [city().eq("Berlin")],
})) {
console.log(lead.name);
}
// Export to CSV
const csv = await client.leads.export({ format: "csv" });
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
});
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
],
});
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"]),
],
});
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);
// Create up to 100 leads at once
const results = await client.leads.batchCreate(leads);
// Delete by IDs
await client.leads.batchDelete(["cl_...", "cl_..."]);

Full source and examples: github.com/lbframe/sdk-typescript