invoice API for Rust
Invoice API for Rust
Create an invoice from Rust with reqwest and serde. Treat a non-success status as an error before you deserialize the invoice.
Base URL https://invoicetxt.com Auth Authorization: Bearer itxt_live_…
POST/v1/invoices
POST the invoice
This example uses reqwest with the json feature and tokio. The key is read from the environment. The typed response only needs the fields you store.
use serde_json::json;
let key = std::env::var("INVOICETXT_API_KEY")?;
let client = reqwest::Client::new();
let invoice: serde_json::Value = client
.post("https://invoicetxt.com/v1/invoices")
.bearer_auth(key)
.json(&json!({
"client": "Greenway Gardens",
"due": "net 14",
"items": [{"description": "Garden maintenance", "quantity": 6, "rate": 55}]
}))
.send().await?
.error_for_status()?
.json().await?;Where to call it
Call this from the service that already knows the job is finished, such as the endpoint your crew app hits when they mark a visit complete. Store invoice[\"id\"] and invoice[\"url\"] on the job. Send the URL by SMS from your existing messaging provider. InvoiceTXT does not send the carrier message for you.