<p align="center"><a href="https://withone.ai"><img src="https://cdn.jsdelivr.net/npm/@withone/sdk/banner.svg" alt="One" width="640"></a></p>
<h1 align="center">One for Rust</h1>
<p align="center">The Rust SDK for <a href="https://withone.ai">One</a>, the unified API for third-party platforms.</p>
<p align="center"><a href="https://withone.ai">Website</a> · <a href="https://withone.ai/docs">Docs</a> · <a href="https://withone.ai/knowledge">Platforms</a> · <a href="https://app.withone.ai">Dashboard</a></p>
## What this crate is
[One](https://withone.ai) connects your users' accounts on over a thousand platforms (Gmail, Slack, GitHub, Salesforce and the rest) and lets you call any of their actions through one API, with credentials, token refresh and routing handled for you.
`withone` is the client: authentication, connections, retries, webhooks and the operation every action runs through. Each platform's typed actions ship as their own crate, `withone-<platform>`, so you add only the platforms you call.
## Install
```bash
cargo add withone withone-gmail
```
The library is imported as `one`.
## Quick start
1. Create a secret key in the [One dashboard](https://app.withone.ai/settings/api-keys) and export it as `ONE_SECRET`.
2. Connect an account in the [dashboard](https://app.withone.ai) and copy its connection key.
3. Run an action on that connection:
```rust
use one::One;
use withone_gmail as gmail;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let one = One::from_env()?;
let response = one
.connection(std::env::var("ONE_CONNECTION_KEY")?)
.run(gmail::send_users_draft_email().user_id("me").id("r-1234567890"))
.await?;
let sent: serde_json::Value = response.json()?;
println!("{sent:#}");
Ok(())
}
```
## What the client does
- **Typed actions.** Each action takes exactly the fields it needs, required ones enforced when you build, and the client routes each field to the path, query, headers or body. A list sends its query key once per item and its header items joined by commas; an object query value is refused as `Error::InvalidInput`.
- **Escape hatches.** Turn an action into an operation with `into_operation()` to merge extra body, query or header fields, set a retry schedule or hook errors.
- **Credentials.** `One::new` takes a secret key, `One::builder().access_token(..)` acts on a user's OAuth grant, and `One::from_env` reads `ONE_SECRET` or `ONE_ACCESS_TOKEN`.
- **Webhooks.** Verify and dispatch One's webhook deliveries with typed handlers per event.
## Platforms
Every platform One supports is listed on [withone.ai/knowledge](https://withone.ai/knowledge), with its actions and how each behaves. Its crate is `withone-<platform>` on [crates.io](https://crates.io/search?q=withone-).
The same client is on npm as [`@withone/sdk`](https://www.npmjs.com/package/@withone/sdk).
## License
MIT