
box-open-sdk (Rust)

An open source, community-built Box API client for Rust — typed models for the whole
Box surface, one async manager per API area behind a single Client, and a
reqwest/tokio runtime with retry, exponential backoff, Retry-After
handling, and automatic token refresh.
Not affiliated with, authorized, or endorsed by Box, Inc. "Box" is a
trademark of Box, Inc. This is an independent, generated client.
Install
[dependencies]
box-open-sdk = "0.2"
tokio = { version = "1", features = ["full"] }
Quickstart
Authenticate, look up the current user, create a folder, upload a file, extract
its fields with Box AI, tag it with metadata, and query for it — end to end.
Request bodies derive Default, so only the fields you set are named:
use box_open_sdk::auth::{Auth, CcgConfig};
use box_open_sdk::client::Client;
use box_open_sdk::models::schemas;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new(Auth::client_credentials(CcgConfig {
client_id: "CLIENT_ID".into(),
client_secret: "CLIENT_SECRET".into(),
enterprise_id: "ENTERPRISE_ID".into(),
..Default::default()
}));
let me = client.users.get_me(None).await?;
println!("authenticated as {}", me.id);
let folder = client
.folders
.create(
schemas::FolderCreateRequest {
name: "Invoices".into(),
parent: schemas::AttributesParent { id: "0".into() },
..Default::default()
},
None,
)
.await?;
let uploaded = client
.uploads
.upload_file(
schemas::FileContentCreateRequest {
attributes: schemas::PostFileContentAttributes {
name: "invoice.pdf".into(),
parent: schemas::AttributesParent { id: folder.id.clone() },
..Default::default()
},
file: b"<file bytes>".to_vec(),
},
None,
)
.await?;
let file_id = uploaded.entries.unwrap_or_default().remove(0).id;
let answer = client
.ai
.extract(schemas::AiExtract {
prompt: "Extract the invoice number and total amount.".into(),
items: vec![schemas::AiItemBase {
id: file_id.clone(),
r#type: schemas::AiCitationType(schemas::AiCitationType::FILE.into()),
..Default::default()
}],
..Default::default()
})
.await?;
println!("{answer:?}");
client
.file_metadata
.create_file_metadata(
file_id.clone(),
schemas::GetFileIdMetadataIdIdScope(schemas::GetFileIdMetadataIdIdScope::ENTERPRISE.into()),
"invoiceData".into(),
std::collections::HashMap::from([
("invoiceNumber".to_string(), serde_json::json!("INV-0042")),
("total".to_string(), serde_json::json!(1250)),
]),
)
.await?;
let results = client
.search
.query_by_metadata(schemas::MetadataQuery {
from: "enterprise_0.invoiceData".into(),
ancestor_folder_id: folder.id.clone(),
..Default::default()
})
.await?;
println!("{results:?}");
Ok(())
}
Authentication
Box's four auth flows all live in box_open_sdk::auth — developer token,
client credentials (CCG), OAuth 2.0 (with a pluggable refresh-token
store), and JWT (server auth). See docs/auth.md.
Pagination
List endpoints return an auto-paging stream — advancing the cursor and fetching
the next page is handled for you. See docs/pagination.md.
Documentation
API reference on docs.rs; the docs/
tree carries the per-manager reference — a call snippet for every method — and
the authentication, pagination, and errors guides.
License
MIT. Generated by box-gantry.