QuickBooks Online Types for Rust
The quickbooks-types crate provides strongly typed Rust models for QuickBooks Online (QBO) API entities and report types. It focuses on data structures, validation helpers, and report parameter builders. Network access and API calls are intentionally out of scope—use your preferred HTTP client alongside these types.
- Crate: quickbooks-types
- Version: 0.1.1
- License: MIT
QuickBooks API docs: https://developer.intuit.com/app/developer/qbo/docs/get-started
Status and scope
This crate:
- Defines data models for common QBO entities (e.g., Invoice, Customer, Vendor, Item, etc.)
- Provides traits that capture operation preconditions such as can_create, can_full_update, can_sparse_update, etc.
- Includes helper types for lines, references, taxes, contact info, and metadata
- Implements a reports module with rich report parameter builders and types
- Offers optional ergonomics via a builder feature, and an optional reports+Polars integration feature
This crate does not:
- Make HTTP requests
- Provide an async runtime or HTTP client
- Offer a general SQL-like query builder for QBO entities
Installation
[]
= "0.1.1"
Optional features:
- builder: derive Builder types and add convenience constructors for top-level entities
- polars: enable report parsing helpers that integrate with Polars (exposes
reports::QBPolarsError)
Examples:
[]
= { = "0.1.1", = ["builder"] }
# or
= { = "0.1.1", = ["polars"] }
Modules and re-exports
- Entities re-exported at crate root:
- Account, Attachable, Bill, BillPayment, CompanyInfo, Customer, Employee, Estimate, Invoice, Item, Payment, Preferences, SalesReceipt, Vendor
- Nested modules:
common: shared value types (e.g.,NtRef,MetaData, contact and address types, taxes)reports: report data structures and parameter buildersreports::types: report enum-like structs and<Report>Paramsreports::params: reusable parameter enums and typed IDsreports::models: report models (e.g.,Report,Row,ColData)reports::polars(feature = "polars"): Polars integration
Quick start: Entities
Basic construction and serialization of an invoice:
use NaiveDate;
use serde_json;
use ;
use NtRef;
// minimal invoice with one sales item line
let invoice = Invoice ;
let json = to_string_pretty.unwrap;
println!;
Operation checks (traits):
use ;
let mut invoice = default;
assert!; // missing required fields (customer_ref + line)
invoice.customer_ref = Some;
invoice.line = Some;
assert!; // line must be a non-empty collection with amounts
// simulate entity read from QBO
invoice.id = Some;
invoice.sync_token = Some;
assert!; // ID is set
assert!; // still fails creation rules
// deletion requires "has_read" (ID + sync_token)
assert!;
Convert entities to references (NtRef):
use ;
let mut customer = default;
customer.id = Some;
customer.display_name = Some;
let customer_ref = customer.to_ref.unwrap;
// customer_ref.name == Some("John Doe"), customer_ref.value == Some("CUST-123")
Builder feature
Enable the builder feature to get derived builders for most entity types and a convenience ::new() associated function for top-level entities (e.g., Invoice::new() returns an InvoiceBuilder).
[]
= { = "0.1.1", = ["builder"] }
use NaiveDate;
use NtRef;
use ;
use ;
let invoice = new
.customer_ref
.txn_date
.line
.build
.unwrap;
assert!;
Attachable convenience (builder):
use Attachable;
Reports
The reports module provides:
- Richly-typed report models:
reports::models::{Report, Row, ColData, ...} - Strongly-typed parameter builders per report:
reports::types::<Report>Params - Common enums and ID wrappers for parameters:
reports::params::*
Build a query string for a report:
use NaiveDate;
use *;
use *;
let balance_sheet = new
.accounting_method
.start_date
.end_date
.date_macro
.summarize_column_by;
println!;
// -> accounting_method=Cash&start_date=2024-01-01&end_date=2024-12-31&date_macro=This Fiscal Year&summarize_column_by=Month
Another example:
use NaiveDate;
use *;
use *;
let ap_aging = new
.as_of_date
.aging_method
.vendor
.column
.column
.column;
println!;
Parsing a report result:
use Report;
let json = r#"{
"Header": { "ReportName": "BalanceSheet" },
"Columns": { "Column": [ { "ColTitle": "Total", "ColType": "Money" } ] },
"Rows": { "Row": [] }
}"#;
let report: Report = from_str.unwrap;
assert_eq!;
Polars integration (feature = "polars"):
- Enables
reports::polarshelpers andreports::QBPolarsError - Provide your own conversion to Polars DataFrames depending on your use case
Entities included
Top-level entities for which QBItem is implemented and a Display impl is provided:
- Account, Attachable, Bill, BillPayment, CompanyInfo, Customer, Employee, Estimate, Invoice, Item, Payment, Preferences, SalesReceipt, Vendor
Supporting value types (non-exhaustive):
common:NtRef,MetaData,Addr,Email,PhoneNumber,WebAddr,TxnTaxDetail,LinkedTxn, and othersline:Line,LineDetailand its variants (e.g.,SalesItemLineDetail,SubTotalLineDetail, etc.),LineField(alias forVec<Line>)
Operation traits (selected):
QBCreatable:can_create(&self) -> bool– entity meets required fields for creationQBReadable:can_read(&self) -> bool– true if ID is presentQBDeletable:can_delete(&self) -> bool– default requires both ID and sync_tokenQBFullUpdatable:can_full_update(&self) -> bool– type-specific requirementsQBSparseUpdateable:can_sparse_update(&self) -> bool– typicallycan_full_update()+sparse == trueQBVoidable:can_void(&self) -> bool– default requires both ID and sync_tokenQBSendable/QBPDFable: marker traits for entities that can be emailed / retrieved as PDF in QBOQBToRef:to_ref(&self) -> Result<NtRef, QBTypeError>– convert to reference usable in other entities
Note: These methods validate local preconditions only; they do not contact QBO.
Errors
use QBTypeError;
Tips
- IDs and
sync_tokenare required for delete and void operations (has_read()check) - Builders (feature = "builder") return
Result<_, QBTypeError>onbuild() - Some enums contain placeholder or minimal variants where the QBO surface is large; open an issue or PR to extend as needed
Contributing
Issues and PRs are welcome. If you need additional entities, fields, or extended report handling, feel free to propose a change.
License
MIT. See the LICENSE file for details.