Rust SDK
The tomba crate is the official Rust client for the Tomba API. All methods hang off one blocking client, and each method sends one request.
Requirements
- Rust 1.85 or later.
Cargo.tomldeclaresrust-version = "1.63", but the current releases of the crate's dependencies (reqwest0.12 and the crates it pulls in) need Rust 1.85. - On Linux, OpenSSL development headers, for
reqwest's default TLS backend.
Install
Code
The client uses reqwest::blocking, so each call blocks the current thread. In async code, run calls with tokio::task::spawn_blocking.
Authenticate
Create an API key and copy your secret on the API keys page, then export both:
Code
The SDK doesn't read environment variables. Pass the values in a TombaConfig to Tomba::init, and the client sends them as the X-Tomba-Key and X-Tomba-Secret headers. Key expiry and rotation are covered in Authentication.
First request
Find the email address of a person at a company:
Code
Every method returns Result<TombaResponse, TombaError>. TombaResponse.data is the JSON body as a serde_json::Value, and TombaResponse.rate_limit holds the rate limit headers. The API wraps its payload in its own data object (Response format), so the address is at result.data["data"]["email"].
Errors
TombaError has four variants:
| Variant | When |
|---|---|
Api { message, code } | The API responded with status 400 or higher. code is the HTTP status; message is the raw response body, for example {"errors":{"type":"authentication_failed","message":"Please enter a valid KEY.","code":400}}. |
Http(reqwest::Error) | The request failed before a response arrived, for example a timeout. |
Parse(serde_json::Error) | A successful response body isn't JSON. |
InvalidParam(String) | A bulk method got an unknown bulk type. No request is sent. |
Code
To branch on errors.type, parse message with serde_json::from_str. Each type is described in Errors.
Rate limits and retries
The SDK doesn't retry. result.rate_limit holds the response's rate limit headers as Option<String> fields: x_second_rate_limit, x_minute_rate_limit, x_daily_rate_limit, x_minute_request_left, x_daily_request_left, x_minute_reset_seconds, x_daily_reset_seconds, retry_after, rate_limit_policy, and rate_limit. tomba::parse_rate_limit reads the same headers from a reqwest::header::HeaderMap.
A 429 returns TombaError::Api with code 429 and no headers. Wait before retrying as described in Handle 429 responses.
Requests time out after 120 seconds; the timeout isn't configurable.
Method reference
All methods are on Tomba, the value returned by Tomba::init, and return Result<TombaResponse, TombaError>. Request bodies are &serde_json::Value.
| Method | Endpoint |
|---|---|
account() | GET /me |
usage() | GET /usage |
logs(page: Option<u32>, limit: Option<u32>) | GET /logs |
domain_search(domain: &str, enrich_mobile: Option<bool>, webhook_url: Option<&str>) | GET /domain-search |
email_finder(domain: &str, first_name: &str, last_name: &str, webhook_url: Option<&str>) | GET /email-finder |
author_finder(url: &str, webhook_url: Option<&str>) | GET /author-finder |
linkedin_finder(url: &str, enrich_mobile: Option<bool>, full: Option<bool>, webhook_url: Option<&str>) | GET /linkedin |
email_format(domain: &str) | GET /email-format |
count(domain: &str) | GET /email-count |
email_verifier(email: &str, webhook_url: Option<&str>, enrich_mobile: Option<bool>) | GET /email-verifier |
email_sources(email: &str) | GET /email-sources |
phone_finder(email: &str, webhook_url: Option<&str>) | GET /phone-finder |
phone_validator(phone: &str) | GET /phone-validator |
status(domain: &str) | GET /domain-status |
autocomplete(query: &str) | GET /domain-suggestions |
similar_domains(domain: &str) | GET /similar |
list_keys() | GET /keys |
get_key(id: &str) | GET /keys/{id} |
create_key(body: &Value) | POST /keys |
delete_key(id: &str) | DELETE /keys/{id} |
list_leads(domain: Option<&str>) | GET /leads |
get_lead(id: &str) | GET /leads/{id} |
create_lead(body: &Value) | POST /leads |
update_lead(id: &str, body: &Value) | PUT /leads/{id} |
delete_lead(id: &str) | DELETE /leads/{id} |
list_leads_lists() | GET /leads_lists |
get_leads_list(id: &str) | GET /leads_lists/{id} |
create_leads_list(body: &Value) | POST /leads_lists |
update_leads_list(id: &str, body: &Value) | PUT /leads_lists/{id} |
delete_leads_list(id: &str) | DELETE /leads_lists/{id} |
list_bulk(bulk_type: &str) | GET /bulk/{type} |
create_bulk(bulk_type: &str, body: &Value) | POST /bulk/{type} |
get_bulk(bulk_type: &str, id: &str) | GET /bulk/{type}/{id} |
launch_bulk(bulk_type: &str, id: &str) | PUT /bulk/{type}/{id} |
bulk_progress(bulk_type: &str, id: &str) | GET /bulk/{type}/{id}/progress |
rename_bulk(bulk_type: &str, id: &str, name: &str) | PUT /bulk/{type}/{id}/rename |
archive_bulk(bulk_type: &str, id: &str) | DELETE /bulk/{type}/{id}/archive |
delete_bulk(bulk_type: &str, id: &str) | DELETE /bulk/{type}/{id}/delete |
bulk_type is the {type} segment listed in Bulk types; the order of calls is described in Lifecycle. create_bulk sends a JSON body, so it can't create jobs that need a CSV upload, such as email finder jobs.
Source
github.com/tomba-io/rust (Apache-2.0).