Skip to content

Rust SDK

[dependencies]
klozeo = "0.1"
tokio = { version = "1", features = ["full"] }

Requires Rust 1.75+. Async/await via tokio, HTTP via reqwest.

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(())
}
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(),
);
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?;
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();
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),
}
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?;
// 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?;

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