SDKs: Official SDK documentation for TypeScript, Python, Go, and Rust # Go SDK > Official Go client for the Klozeo API. ```bash go get github.com/lbframe/klozeo-sdk-go ``` Requires Go 1.23+. ## Quick start [Section titled “Quick start”](#quick-start) ```go import klozeo "github.com/lbframe/klozeo-sdk-go" client := klozeo.New("sk_live_your_api_key") // Create a lead // Optional string fields use pointers to distinguish "not set" from "empty string" lead, err := client.Create(ctx, &klozeo.Lead{ Name: "Acme Corp", Source: "website", City: "Berlin", Email: klozeo.Ptr("contact@acme.com"), }) // List with filters leads, err := client.List(ctx, klozeo.City().Eq("Berlin"), klozeo.Rating().Gte(4.0), klozeo.Sort(klozeo.FieldRating, klozeo.Desc), klozeo.Limit(20), ) // Iterate all pages (Go 1.23+ range-over-function iterator) for lead, err := range client.Iterator(ctx, klozeo.City().Eq("Berlin")) { if err != nil { log.Fatal(err) } fmt.Println(lead.Name) } // Export to CSV reader, err := client.Export(ctx, klozeo.ExportCSV) ``` ## OR logic [Section titled “OR logic”](#or-logic) Combine `Or()` with standard filters in the same `List()` call: ```go leads, err := client.List(ctx, klozeo.City().Eq("Paris"), // AND city = Paris klozeo.Or().Rating().Gte(4.0), // OR rating >= 4 ) ``` ## Error handling [Section titled “Error handling”](#error-handling) ```go import "errors" resp, err := client.Create(ctx, &klozeo.Lead{Name: "Acme", Source: "web"}) if err != nil { var apiErr *klozeo.APIError if errors.As(err, &apiErr) { switch apiErr.Code { case klozeo.ErrRateLimit: // retry after apiErr.RetryAfter case klozeo.ErrNotFound: // lead not found case klozeo.ErrUnauthorized: // invalid API key } } } ``` ## Notes [Section titled “Notes”](#notes) ```go note, err := client.AddNote(ctx, leadID, "Called back — very interested.") notes, err := client.Notes(ctx, leadID) err = client.DeleteNote(ctx, noteID) ``` ## Batch operations [Section titled “Batch operations”](#batch-operations) ```go // Create up to 100 leads at once results, err := client.BatchCreate(ctx, leads) // Delete by IDs err = client.BatchDelete(ctx, []string{"cl_...", "cl_..."}) ``` ## More [Section titled “More”](#more) Full API reference: [pkg.go.dev/github.com/lbframe/klozeo-sdk-go](https://pkg.go.dev/github.com/lbframe/klozeo-sdk-go) # Python SDK > Official Python client for the Klozeo API. ```bash pip install klozeo ``` Requires Python 3.10+. ## Quick start [Section titled “Quick start”](#quick-start) ```python from klozeo import ( Klozeo, Lead, text_attr, number_attr, city, rating, SortField, SortOrder ) client = Klozeo("sk_live_your_api_key") # Create a lead lead = client.leads.create(Lead( name="Acme Corp", source="website", city="Berlin", email="contact@acme.com", attributes=[ text_attr("industry", "Software"), number_attr("employees", 500), ] )) # List with filters leads = client.leads.list( filters=[city.eq("Berlin"), rating.gte(4.0)], sort_by=SortField.RATING, sort_order=SortOrder.DESC, limit=20, ) # Iterate all pages automatically for lead in client.leads.iterate(filters=[city.eq("Berlin")]): print(lead.name) # Export to CSV import csv, io data = client.leads.export(format="csv") reader = csv.DictReader(io.StringIO(data)) ``` ## Handling errors [Section titled “Handling errors”](#handling-errors) ```python from klozeo import KlozeoError, RateLimitError, AuthError, NotFoundError try: lead = client.leads.create(Lead(name="Acme", source="web")) except RateLimitError as e: print(f"Rate limited. Retry after {e.retry_after}s") except AuthError: print("Invalid or revoked API key") except NotFoundError: print("Lead not found") except KlozeoError as e: print(f"API error {e.status}: {e.message}") ``` ## More [Section titled “More”](#more) Full source and examples: [github.com/lbframe/klozeo-sdk-python](https://github.com/lbframe/klozeo-sdk-python) Package on PyPI: [pypi.org/project/klozeo](https://pypi.org/project/klozeo) # Rust SDK > Official Rust client for the Klozeo API. ```toml [dependencies] klozeo = "0.1" tokio = { version = "1", features = ["full"] } ``` Requires Rust 1.75+. Async/await via `tokio`, HTTP via `reqwest`. ## Quick start [Section titled “Quick start”](#quick-start) ```rust use klozeo::{Client, Lead}; #[tokio::main] async fn main() -> Result<(), klozeo::Error> { let client = Client::new("sk_live_your_api_key"); // Create a lead let resp = client.leads().create( Lead::builder() .name("Acme Corporation") .source("website") .city("San Francisco") .email("contact@acme.com") .rating(4.5) .tags(vec!["enterprise".into(), "saas".into()]) .build(), ).await?; println!("Created: {}", resp.id); // List with filters use klozeo::filters::{city, rating, sort}; let leads = client.leads().list(vec![ city().eq("Berlin"), rating().gte(4.0), sort().by("rating").desc(), ]).await?; // Stream all pages automatically use futures::StreamExt; let mut stream = client.leads().stream(vec![city().eq("Berlin")]); while let Some(lead) = stream.next().await { println!("{}", lead?.name); } Ok(()) } ``` ## Client options [Section titled “Client options”](#client-options) ```rust use klozeo::{Client, ClientConfig}; use std::time::Duration; let client = Client::with_config( "sk_live_your_api_key", ClientConfig::builder() .base_url("https://custom.api.com") // default: https://api.klozeo.com/api/v1 .timeout(Duration::from_secs(30)) .max_retries(3) // retries on 429 / 5xx .build(), ); ``` ## Filters [Section titled “Filters”](#filters) ```rust use klozeo::filters::{city, rating, tags, or, attr}; let leads = client.leads().list(vec![ city().eq("Paris"), or().city().eq("Lyon"), // OR city = Lyon rating().gte(4.0), tags().contains("enterprise"), attr("industry").eq("Software"), // dynamic attribute ]).await?; ``` ## Attribute helpers [Section titled “Attribute helpers”](#attribute-helpers) ```rust use klozeo::Attribute; let lead = Lead::builder() .name("Acme") .source("web") .attributes(vec![ Attribute::text("industry", "Software"), Attribute::number("employees", 500.0), Attribute::bool("verified", true), Attribute::list("products", vec!["CRM".into(), "ERP".into()]), ]) .build(); ``` ## Error handling [Section titled “Error handling”](#error-handling) ```rust use klozeo::Error; match client.leads().get("cl_nonexistent").await { Err(Error::NotFound) => println!("Lead not found"), Err(Error::Unauthorized) => println!("Invalid API key"), Err(Error::RateLimit { retry_after }) => { println!("Rate limited. Retry after {retry_after}s"); } Err(Error::Api { status, message, .. }) => { println!("API error {status}: {message}"); } Ok(lead) => println!("Got: {}", lead.name), } ``` ## Notes [Section titled “Notes”](#notes) ```rust let note = client.notes().create(lead_id, "Called back — very interested.").await?; let notes = client.notes().list(lead_id).await?; client.notes().delete(note_id).await?; ``` ## Batch operations [Section titled “Batch operations”](#batch-operations) ```rust // Create up to 100 leads at once let results = client.leads().batch_create(leads).await?; // Delete by IDs client.leads().batch_delete(vec!["cl_...", "cl_..."]).await?; ``` ## More [Section titled “More”](#more) Full source and examples: [github.com/lbframe/klozeo-sdk-rust](https://github.com/lbframe/klozeo-sdk-rust) Package on crates.io: [crates.io/crates/klozeo](https://crates.io/crates/klozeo) # TypeScript SDK > Official TypeScript / JavaScript client for the Klozeo API. ```bash npm install @klozeo/sdk ``` Requires Node.js 18+ (or any modern browser). Ships ESM + CJS with full TypeScript types. ## Quick start [Section titled “Quick start”](#quick-start) ```typescript 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" }); ``` ## Client options [Section titled “Client options”](#client-options) ```typescript 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”](#filters) ```typescript 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”](#attribute-helpers) ```typescript 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”](#error-handling) ```typescript 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}`); } } ``` ## Notes [Section titled “Notes”](#notes) ```typescript 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”](#batch-operations) ```typescript // Create up to 100 leads at once const results = await client.leads.batchCreate(leads); // Delete by IDs await client.leads.batchDelete(["cl_...", "cl_..."]); ``` ## More [Section titled “More”](#more) Full source and examples: [github.com/lbframe/klozeo-sdk-typescript](https://github.com/lbframe/klozeo-sdk-typescript) Package on npm: [npmjs.com/package/@klozeo/sdk](https://www.npmjs.com/package/@klozeo/sdk)