Rust
Add the zernio crate and call every Zernio API endpoint from Rust with an async reqwest-based client.
zernio is the official Rust client for the Zernio API, async and built on reqwest. Install it with cargo add zernio. The crate is on crates.io and the source on GitHub.
First call
cargo add zernio
cargo add tokio --features macros,rt-multi-thread
export ZERNIO_API_KEY="sk_..."Endpoints are free functions grouped by module under zernio::apis, and every call takes a Configuration carrying the API key. This program publishes a post to a connected LinkedIn account; accountId comes from GET /v1/accounts (Step 4 of the quickstart).
use zernio::apis::{configuration::Configuration, posts_api, Error};
use zernio::models::{CreatePostRequest, CreatePostRequestPlatformsInner};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut config = Configuration::new();
config.bearer_access_token = Some(std::env::var("ZERNIO_API_KEY")?);
let request = CreatePostRequest {
content: Some("Hello from the Zernio Rust SDK".to_string()),
platforms: Some(vec![
CreatePostRequestPlatformsInner::new("linkedin".to_string(), "66b2e19d8c3f5a7e9d0b1c2d".to_string()),
]),
publish_now: Some(true),
..Default::default()
};
// The third argument is the x-request-id idempotency key; None sends none.
match posts_api::create_post(&config, request, None).await {
Ok(post) => println!("{post:?}"),
Err(Error::ResponseError(resp)) => {
eprintln!("API error {}: {}", resp.status, resp.content);
}
Err(e) => eprintln!("transport error: {e}"),
}
Ok(())
}Response (201):
{
"post": {
"_id": "65f1c0a9e2b5af0012ab34cd",
"status": "published",
"platforms": [
{
"platform": "linkedin",
"status": "published",
"platformPostUrl": "https://www.linkedin.com/feed/update/..."
}
]
}
}Methods
Each function is named after the operationId of the endpoint it calls, in snake_case, in a module per API tag under zernio::apis: posts_api::create_post, accounts_api::list_accounts, profiles_api::create_profile, analytics_api::get_analytics, webhooks_api::create_webhook_settings, workflows_api::create_workflow. Request models live in zernio::models.
Method reference
Every endpoint and model in the GitHub README
API reference
Request and response schemas for every endpoint
How it behaves
Configuration also holds the base path and the HTTP client
use std::time::Duration;
let mut config = Configuration::new();
config.bearer_access_token = Some(std::env::var("ZERNIO_API_KEY")?);
config.base_path = "https://zernio.com/api".to_string();
config.client = reqwest::Client::builder().timeout(Duration::from_secs(30)).build()?;base_path defaults to https://zernio.com/api; set it to point at another host. client is the reqwest::Client every call runs on, so timeouts, proxies and connection pooling are set on the builder; add reqwest to your own Cargo.toml to build one.
create_post accepts an idempotency key
The third argument is Option<&str> sent as the x-request-id header; a retry with the same UUID and the same content within 24 hours returns the original post instead of a duplicate-content 409. To protect a retry whose body can differ, send an Idempotency-Key header instead (idempotency).
Errors are zernio::apis::Error<E>
Every call returns Result<T, Error<E>>, where E is the operation's typed error. A non-2xx response is Error::ResponseError with status and the raw content; anything else (DNS, TLS, timeout) is a transport error. Running the first call twice within 24 hours returns ResponseError with status 409, because the same content is already published to that account:
{
"error": "This exact content is already scheduled, publishing, or was posted to this account within the last 24 hours.",
"details": {
"accountId": "66b2e19d8c3f5a7e9d0b1c2d",
"platform": "linkedin",
"existingPostId": "65f1c0a9e2b5af0012ab34cd"
}
}Change the content, or send an idempotency key. The error handling guide lists every code.
Related
- Quickstart: API key, profile, account and first post in 5 calls.
- Idempotency: what the
x_request_idargument does. - Error handling: the envelope inside
ResponseError. - Rate limits: what a
429means and how to back off. - SDKs: the other 7 clients.