Creare clienti su Fatture in Cloud con Rust
Al momento, febbraio 2026, Fatture in Cloud non ha un SDK dedicato a Rust.
Quindi come possiamo creare clienti dalla nostra applicazione?
Usando l'API con richieste HTTP.
Queste sono le dipendenze che ci servono:
[dependencies]
reqwest = { version = "0.13.2", features = ["json"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
Qui sotto il codice; come spesso accade, ho messo tutto insieme per comodità:
use reqwest::header::{AUTHORIZATION, CONTENT_TYPE, HeaderMap, HeaderValue};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
struct Client {
name: String,
code: Option<String>,
vat_number: Option<String>,
tax_code: Option<String>,
address_street: Option<String>,
address_postal_code: Option<String>,
address_city: Option<String>,
address_province: Option<String>,
email: Option<String>,
}
#[derive(Serialize, Debug)]
struct CreateClientRequest {
data: Client,
}
#[derive(Deserialize, Debug)]
struct ClientResponse {
id: i32,
name: String,
// ALTRI CAMPI
}
#[derive(Deserialize, Debug)]
struct CreateClientResponse {
data: ClientResponse,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let token = "TOKEN";
let company_id = "COMPANY ID";
let url = format!(
"https://api-v2.fattureincloud.it/c/{}/entities/clients",
company_id
);
let new_client = CreateClientRequest {
data: Client {
name: "Mario Rossi S.r.l.".to_string(),
code: Some("CLIENT-001".to_string()),
vat_number: Some("IT12345678901".to_string()),
tax_code: Some("12345678901".to_string()),
address_street: Some("Via Roma 1".to_string()),
address_postal_code: Some("00100".to_string()),
address_city: Some("Roma".to_string()),
address_province: Some("RM".to_string()),
email: Some("mario.rossi@example.com".to_string()),
},
};
let mut headers = HeaderMap::new();
let auth_value = format!("Bearer {}", token);
headers.insert(AUTHORIZATION, HeaderValue::from_str(&auth_value)?);
headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));
let client = reqwest::Client::new();
let response = client
.post(&url)
.headers(headers)
.json(&new_client)
.send()
.await?;
if response.status().is_success() {
let success_body: CreateClientResponse = response.json().await?;
let new_id = success_body.data.id;
println!("Cliente creato con successo! ID assegnato: {}", new_id);
println!("Nome confermato: {}", success_body.data.name);
} else {
let status = response.status();
let error_details = response.text().await?;
eprintln!("Errore {}: {}", status, error_details);
}
Ok(())
}
Ricordatevi di sostituire il company id e il token con i vostri.
Se invece usate Oauth2, sicuramente dovete fare qualche modifica.
Enjoy!
rust reqwest tokio serde json fatture cloud
Commentami!