{"openapi":"3.1.0","info":{"title":"POST /api/v1/transactions/bulk-upload","version":"1.0.0","description":"Bulk upload transactions to new source account"},"servers":[{"url":"https://api.ondayzero.com","description":"Production"}],"paths":{"/api/v1/transactions/bulk-upload":{"post":{"tags":["transactions"],"summary":"Bulk upload transactions to new source account","description":"Upload historical transactions from a CSV/Excel file to a new source account.\n\n**Workflow (via Temporal for durability):**\n\n1. Gets/creates ledger\n2. Reads transactions from the CSV/Excel file in S3\n3. Creates Transaction + Journal Entry rows with categorization\n4. Runs AI categorization pass for uncategorized transactions\n\n**Supported File Formats:** .csv, .xlsx, .xls\n\n**CSV/Excel Columns (flexible naming):**\n- date/datetime/transaction_date: Transaction date (YYYY-MM-DD or ISO format)\n- amount/transaction_amount/value: Amount in dollars (positive or negative)\n- description/memo/name: Transaction description\n- category/ledger/account (optional): the ledger to book each row to. A name\n  that matches no ledger refuses the file (400 `VALIDATION_570`, nothing\n  imported) unless `allow_unmatched_categories` is true, which imports those\n  rows to Uncategorized. Rows are never dropped.\n\n**Returns:** Workflow ID and status. The upload runs in the background via Temporal.\nIf interrupted, the workflow will resume from where it left off.","operationId":"bulk_upload_transactions","parameters":[{"name":"authorization","in":"header","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Authorization"}},{"name":"x-business-id","in":"header","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"X-Business-Id"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/BulkTransactionUploadRequest"},"example":{"financial_account_type":"credit_card","ledger_name":"My Old Credit Card XXXX","s3_key":"uploads/business123/transactions.csv"}}}},"responses":{"201":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope_BulkTransactionUploadResponse_"}}}},"400":{"description":"Bad Request - Invalid input","content":{"application/json":{"example":{"error":"validation_error","message":"Validation failed: due_date: Input should be a valid date","errors":{"due_date":"Input should be a valid date"},"code":"GEN_002","request_id":"3f0e7c2a-9b4d-4e1a-8c6f-2d5b7a1e9c30"},"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized - Missing or expired token, an MCP OAuth token used against the REST API, or no access to this business","content":{"application/json":{"example":{"error":"unauthorized","message":"Authentication required","code":"AUTH_001","request_id":"3f0e7c2a-9b4d-4e1a-8c6f-2d5b7a1e9c30"},"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden - Insufficient permissions","content":{"application/json":{"example":{"error":"forbidden","message":"You don't have permission to access this resource","code":"AUTH_002","request_id":"3f0e7c2a-9b4d-4e1a-8c6f-2d5b7a1e9c30"},"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"error":"validation_error","message":"Validation failed: amount: Input should be a valid integer","errors":{"amount":"Input should be a valid integer"},"code":"GEN_002","request_id":"3f0e7c2a-9b4d-4e1a-8c6f-2d5b7a1e9c30"}}}}},"x-fastapi-operation-id":"bulk_upload_transactions_api_v1_transactions_bulk_upload_post"}}},"components":{"schemas":{"BulkTransactionUploadRequest":{"properties":{"ledger_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Ledger Id","description":"Optional: UUID of existing ledger to use. If provided, ledger creation is skipped and ledger_name/ledger fields are ignored."},"ledger_name":{"anyOf":[{"type":"string","maxLength":255,"minLength":1},{"type":"null"}],"title":"Ledger Name","description":"Display name for the new ledger (required if ledger_id not provided, e.g., 'My Old Credit Card XXXX')"},"source_account_name":{"anyOf":[{"type":"string","maxLength":255,"minLength":1},{"type":"null"}],"title":"Source Account Name","description":"Optional: Display name for the source account. Defaults to ledger name if not provided."},"business_personal":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Business Personal","description":"Whether the source account is a business or personal account. 'business' (default) for company transactions, 'personal' for owner draws/contributions.","default":"business"},"invert_transaction_amounts":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Invert Transaction Amounts","description":"If true, transaction amounts are inverted during import. Useful when CSV has opposite sign convention.","default":false},"s3_key":{"type":"string","minLength":1,"title":"S3 Key","description":"S3 key of the CSV file containing transactions"},"start_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Start Date","description":"Optional: Only upload transactions on or after this date (YYYY-MM-DD). Filters transactions before upload."},"end_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"End Date","description":"Optional: Only upload transactions on or before this date (YYYY-MM-DD). Filters transactions before upload."},"check_duplicates":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Check Duplicates","description":"If true, checks for duplicate transactions before uploading. Duplicates are skipped.","default":true},"duplicate_match_fields":{"anyOf":[{"items":{"type":"string"},"type":"array"},{"type":"null"}],"title":"Duplicate Match Fields","description":"Fields to use for duplicate detection: 'amount', 'date', 'description'. Defaults to all three.","default":["amount","date","description"]},"skip_categorization":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Skip Categorization","description":"If true, skip post-upload bank rules and AI categorization. Journal entries still post during import — to the mapped category column when provided, otherwise to Uncategorized Expense/Income. Only honored on the local accounting engine.","default":false},"generate_bank_rules":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Generate Bank Rules","description":"If true (default), learn bank rules from the categorized transactions so future transactions auto-categorize. Ignored when skip_categorization is true.","default":true},"currency":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Currency","description":"Currency for this account (USD, CAD, AUD, EUR, or GBP). Defaults to business default.","default":"USD"},"editable":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Editable","description":"If true, journal entries can be manually posted to this account.","default":true},"type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Type","description":"Account type: asset, liability, equity, revenue, expense. Required in Custom Mode."},"description":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Description","description":"Optional description of the account's purpose."},"status":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Status","description":"Account status: 'active' or 'inactive'. Inactive accounts hidden from dropdowns.","default":"active"},"debit_credit":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Debit Credit","description":"Normal balance: 'debit' (assets/expenses) or 'credit' (liabilities/equity/revenue). Required in Custom Mode."},"sort_code":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Sort Code","description":"Sort code for chart ordering (e.g., '1000' for assets, '4000' for revenue). Required in Custom Mode."},"sub_type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Sub Type","description":"Sub-classification (current_assets, operating_expenses, etc.). Required in Custom Mode."},"report_cash_flow":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Report Cash Flow","description":"Include in cash flow statement. Required in Custom Mode."},"financial_account_type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Financial Account Type","description":"Templated Mode: bank_account, credit_card, payments, payroll, loan, prepaid_card, accounts_receivable, accounts_payable."},"parent_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Parent Id","description":"UUID of parent ledger for sub-accounts (e.g., 'Operating Expenses' → 'Office Supplies')."},"column_mapping":{"anyOf":[{"additionalProperties":{"type":"string"},"type":"object"},{"type":"null"}],"title":"Column Mapping","description":"User-supplied mapping from DayZero field names to CSV column names. Keys: 'date', 'amount', 'description', and optional 'category' (aliases: ledger, ledger_name, account, account_name, category_name). Values: the CSV header to use. When provided, auto-detection is skipped."},"only_missing_from_diff":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Only Missing From Diff","description":"If true, compare the file with ledger_id first (the same diff as POST /transactions/bulk-upload/diff, re-run now) and import only the rows missing from the ledger. Ambiguous rows (same amount, nothing else agrees) are NOT imported — list them in include_row_numbers instead. Requires ledger_id; the exact-match duplicate check is skipped because the diff already did it.","default":false},"include_row_numbers":{"anyOf":[{"items":{"type":"integer","minimum":2.0},"type":"array","maxItems":100000},{"type":"null"}],"title":"Include Row Numbers","description":"Import only these spreadsheet rows (header = row 1, first data row = 2), e.g. the diff's missing_row_numbers plus any ambiguous rows you checked. The exact-match duplicate check is skipped."},"date_tolerance_days":{"anyOf":[{"type":"integer","maximum":10.0,"minimum":0.0},{"type":"null"}],"title":"Date Tolerance Days","description":"only_missing_from_diff: days a ledger date may differ from the file's (default 3)."},"status_column":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Status Column","description":"only_missing_from_diff: header of the file's settled/pending status column (auto-detected from status/transaction_status/state when omitted)."},"exclude_statuses":{"anyOf":[{"items":{"type":"string"},"type":"array"},{"type":"null"}],"title":"Exclude Statuses","description":"Skip file rows whose status is one of these, case-insensitive (e.g. ['Pending']). Applies to only_missing_from_diff."},"allow_unmatched_categories":{"type":"boolean","title":"Allow Unmatched Categories","description":"Rows whose category names no ledger are refused by default (400 VALIDATION_570, nothing imported, every row listed with the nearest ledger names). Set true to import them to Uncategorized instead. A blank category is not affected.","default":false}},"type":"object","required":["s3_key"],"title":"BulkTransactionUploadRequest","description":"Request schema for bulk transaction upload.\n\nUpload historical transactions from a CSV file to a new source account.\nThe workflow creates a ledger (or uses existing), source account, posts transactions,\nand imports the resulting journal entries.\n\n**Two modes:**\n\n1. **Use Existing Ledger** (if ledger_id is provided):\n   - Provide `ledger_id` of an existing ledger\n   - Ledger creation is skipped\n   - `source_account_name` is optional (defaults to ledger name)\n\n2. **Create New Ledger** (if ledger_id is not provided):\n   - Provide `ledger_name` and ledger fields\n   - Supports two creation modes:\n     - **Templated Mode**: Provide `financial_account_type` (recommended)\n     - **Custom Mode**: Provide all required fields (type, debit_credit, sort_code, sub_type, report_cash_flow)\n\n**Additional Features:**\n- Date range filtering: Use `start_date` and `end_date` to filter transactions before upload\n- Duplicate detection: Use `check_duplicates` (default: true) to automatically skip duplicate transactions\n- Custom duplicate matching: Use `duplicate_match_fields` to customize which fields are used for duplicate detection","examples":[{"financial_account_type":"credit_card","ledger_name":"My Old Credit Card XXXX","s3_key":"uploads/business123/transactions.csv"},{"ledger_id":"019abc12-3456-7890-abcd-ef1234567890","s3_key":"uploads/business123/transactions.csv","source_account_name":"Historical Import Source"},{"debit_credit":"debit","editable":true,"ledger_name":"Historical Bank Account","report_cash_flow":true,"s3_key":"uploads/business123/transactions.csv","sort_code":"1010","sub_type":"current_assets","type":"asset"}]},"BulkTransactionUploadResponse":{"properties":{"workflow_id":{"type":"string","title":"Workflow Id","description":"Temporal workflow ID for tracking progress"},"business_id":{"type":"string","title":"Business Id","description":"Business ID the upload is for"},"ledger_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Ledger Id","description":"UUID of the existing ledger when uploading to one; null for new-ledger uploads"},"ledger_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Ledger Name","description":"Name of the ledger (the new ledger's name, or the existing ledger's name when resolved server-side)"},"status":{"type":"string","title":"Status","description":"Workflow status (typically 'started' initially)"},"executor":{"type":"string","title":"Executor","description":"Execution backend (typically 'temporal')"},"rows_selected":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Rows Selected","description":"Rows the import will post when only_missing_from_diff or include_row_numbers chose them; null = every row"},"diff_summary":{"anyOf":[{"additionalProperties":{"type":"integer"},"type":"object"},{"type":"null"}],"title":"Diff Summary","description":"Counts of the diff run for only_missing_from_diff (same keys as /bulk-upload/diff summary)"}},"type":"object","required":["workflow_id","business_id","status","executor"],"title":"BulkTransactionUploadResponse","description":"Response schema for bulk transaction upload workflow.\n\nReturns workflow information since the upload runs asynchronously via Temporal.\nThe workflow is durable - if interrupted, it will resume from where it left off.","example":{"business_id":"019abc12-3456-7890-abcd-ef1234567890","executor":"temporal","ledger_name":"My Old Credit Card XXXX","status":"started","workflow_id":"bulk-upload-019abc12-1234567890"},"examples":[{"business_id":"019abc12-3456-7890-abcd-ef1234567890","executor":"temporal","ledger_name":"My Old Credit Card XXXX","status":"started","workflow_id":"bulk-upload-019abc12-1234567890"}]},"SuccessEnvelope_BulkTransactionUploadResponse_":{"properties":{"success":{"type":"boolean","title":"Success","default":true},"message":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Message"},"code":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Code"},"data":{"anyOf":[{"$ref":"#/components/schemas/BulkTransactionUploadResponse"},{"type":"null"}]}},"additionalProperties":true,"type":"object","title":"SuccessEnvelope[BulkTransactionUploadResponse]"},"ErrorResponse":{"title":"ErrorResponse","type":"object","description":"Envelope returned by every non-2xx response. Branch on `code` (stable) rather than `message` (human-readable, may change).","required":["error","message","code"],"properties":{"error":{"type":"string","description":"Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`."},"message":{"type":"string","description":"Human-readable explanation, safe to show to end users."},"code":{"type":"string","description":"Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`)."},"request_id":{"type":"string","description":"Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied."},"errors":{"type":"object","additionalProperties":{"type":"string"},"description":"Field-level validation messages keyed by field name. Present on 400/422 validation failures only."}}}},"securitySchemes":{"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"API Token","description":"API token authentication. Format: `Bearer dz_...`"}}},"security":[{"BearerAuth":[]}]}