Classifies invoices using Box AI Extract and organizes them into folders with the Files SDK.
Drop unorganized invoices into a Box folder, click Organize, and watch each file get classified by expense category (Meals, Office Supplies, Travel, etc.) and filed into the matching subfolder — all in real time. A classification-report.json is uploaded to Box when the run completes.
- Bun v1.0+
- A Box app with Client Credentials Grant (CCG) auth enabled
- A free Box developer account with Box AI enabled
bun install
cp .env.example .envEdit .env with your Box credentials:
| Variable | Description |
|---|---|
BOX_CLIENT_ID |
OAuth 2.0 client ID from your Box app |
BOX_CLIENT_SECRET |
OAuth 2.0 client secret |
BOX_ENTERPRISE_ID |
Your Box enterprise ID |
BOX_FOLDER_ID |
Box folder ID containing the invoices to classify |
PORT |
Server port (default 3000) |
bun run startOpen http://localhost:3000.
GET /api/files— lists files inBOX_FOLDER_IDusingfiles.listAll()POST /api/organize— for each file:- Extracts
expense_category,vendor_name, andtotal_amountvia Box AI (files.raw.ai.createAiExtractStructured) - Skips duplicates with
files.exists(dest) - Moves the file into a
{category}/subfolder usingfiles.move() - Uploads a
classification-report.jsonsummary usingfiles.upload()
- Extracts
GET /api/events— SSE stream for real-time progress in the browser
| Method | Purpose |
|---|---|
files.listAll() |
Discover files (handles pagination) |
files.exists() |
Skip already-filed duplicates |
files.move() |
Organize into category folders (auto-creates them) |
files.upload() |
Write classification report back to Box |
hooks.onAction |
Stream SDK activity to the browser via SSE |
files.raw |
Escape hatch for Box AI Extract |
- Files SDK — unified storage API with Box adapter
- Box AI Extract — server-side document classification and metadata extraction
- Bun — runtime and HTTP server