{"openapi":"3.1.0","info":{"title":"POST /api/v1/transactions/bulk-upload/preview","version":"1.0.0","description":"Preview bulk transaction upload"},"servers":[{"url":"https://api.ondayzero.com","description":"Production"}],"paths":{"/api/v1/transactions/bulk-upload/preview":{"post":{"tags":["transactions"],"summary":"Preview bulk transaction upload","description":"Preview and validate a CSV/Excel file before uploading transactions.\n\nThis endpoint allows you to:\n- Validate the file format and structure\n- See how many transactions will be uploaded\n- Preview sample transactions\n- Check for duplicate transactions (optional)\n- Apply date range filtering\n\n**Supported File Formats:** .csv, .xlsx, .xls\n\n**Unknown categories:** a category that matches no ledger is reported in\n`row_errors` (`{row, field, value, suggestions}`, nearest ledger names first)\nand in `errors`; the upload refuses the file until it is fixed or sent with\n`allow_unmatched_categories`.\n\n**Returns:** Validation results, statistics, and sample transactions without actually uploading.","operationId":"preview_bulk_transaction_upload","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/BulkTransactionUploadPreviewRequest"}}}},"responses":{"201":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope_BulkTransactionUploadPreviewResponse_"}}}},"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":"preview_bulk_transaction_upload_api_v1_transactions_bulk_upload_preview_post"}}},"components":{"schemas":{"BulkTransactionUploadPreviewRequest":{"properties":{"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 preview transactions on or after this date (YYYY-MM-DD)."},"end_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"End Date","description":"Optional: Only preview transactions on or before this date (YYYY-MM-DD)."},"check_duplicates":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Check Duplicates","description":"If true, checks for duplicate transactions against existing database records.","default":false},"ledger_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Ledger Id","description":"Optional: Ledger ID to check duplicates against. If not provided, checks all ledgers for the business."},"financial_account_type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Financial Account Type","description":"Financial account type selected for a new ledger. Used by preview to show the same signed amount DayZero will store after import."},"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."}},"type":"object","required":["s3_key"],"title":"BulkTransactionUploadPreviewRequest","description":"Request schema for previewing/validating CSV before upload.\n\nValidates the file structure, parses transactions, applies date filtering,\nand optionally checks for duplicates. Does NOT upload any transactions."},"BulkTransactionUploadPreviewResponse":{"properties":{"success":{"type":"boolean","title":"Success","description":"Whether the file was successfully parsed"},"total_rows":{"type":"integer","title":"Total Rows","description":"Total number of rows in the file (including headers)"},"valid_transactions":{"type":"integer","title":"Valid Transactions","description":"Number of valid transactions found"},"invalid_rows":{"type":"integer","title":"Invalid Rows","description":"Number of rows that failed validation"},"filtered_by_date":{"type":"integer","title":"Filtered By Date","description":"Number of transactions filtered out by date range"},"duplicates_found":{"type":"integer","title":"Duplicates Found","description":"Number of duplicate transactions found (if check_duplicates was true)"},"transactions_to_upload":{"type":"integer","title":"Transactions To Upload","description":"Number of transactions that would be uploaded"},"sample_transactions":{"items":{"additionalProperties":true,"type":"object"},"type":"array","maxItems":10,"title":"Sample Transactions","description":"Sample of first 10 valid transactions (for preview)"},"errors":{"items":{"type":"string"},"type":"array","title":"Errors","description":"List of validation errors encountered"},"row_errors":{"items":{"$ref":"#/components/schemas/BulkUploadRowError"},"type":"array","title":"Row Errors","description":"Every row whose category names no ledger, with the nearest ledger names. The upload refuses the file while this is not empty, unless allow_unmatched_categories is set."},"unmatched_category_rows":{"type":"integer","title":"Unmatched Category Rows","description":"Rows whose category names no ledger. They are counted in transactions_to_upload: with allow_unmatched_categories they import to Uncategorized.","default":0},"warnings":{"items":{"type":"string"},"type":"array","title":"Warnings","description":"List of warnings (e.g., skipped rows)"},"duplicate_transactions":{"anyOf":[{"items":{"additionalProperties":true,"type":"object"},"type":"array"},{"type":"null"}],"title":"Duplicate Transactions","description":"List of duplicate transactions found (if check_duplicates was true)"},"columns":{"anyOf":[{"additionalProperties":true,"type":"object"},{"type":"null"}],"title":"Columns","description":"The file's headers and the column mapping the preview used."}},"type":"object","required":["success","total_rows","valid_transactions","invalid_rows","filtered_by_date","duplicates_found","transactions_to_upload","sample_transactions"],"title":"BulkTransactionUploadPreviewResponse","description":"Response schema for CSV preview/validation.\n\nContains validation results, statistics, sample transactions, and any errors\nor warnings encountered during parsing. Also includes duplicate detection\nresults if check_duplicates was enabled.","example":{"duplicates_found":5,"errors":[],"filtered_by_date":2,"invalid_rows":3,"sample_transactions":[{"amount":-125.5,"date":"2024-01-15","description":"Office Supplies - Staples"}],"success":true,"total_rows":150,"transactions_to_upload":138,"valid_transactions":145,"warnings":["Row 5: Invalid date format","Row 12: Missing amount"]},"examples":[{"duplicates_found":5,"errors":[],"filtered_by_date":2,"invalid_rows":3,"sample_transactions":[{"amount":-125.5,"date":"2024-01-15","description":"Office Supplies - Staples"}],"success":true,"total_rows":150,"transactions_to_upload":138,"valid_transactions":145,"warnings":["Row 5: Invalid date format","Row 12: Missing amount"]}]},"BulkUploadRowError":{"properties":{"row":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Row","description":"Spreadsheet line (the header is line 1)."},"field":{"type":"string","title":"Field","description":"The column at fault, e.g. category."},"value":{"type":"string","title":"Value","description":"What the file says."},"suggestions":{"items":{"type":"string"},"type":"array","title":"Suggestions","description":"Nearest valid values, best first."}},"type":"object","required":["field","value"],"title":"BulkUploadRowError","description":"One upload row the import cannot place as written."},"SuccessEnvelope_BulkTransactionUploadPreviewResponse_":{"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/BulkTransactionUploadPreviewResponse"},{"type":"null"}]}},"additionalProperties":true,"type":"object","title":"SuccessEnvelope[BulkTransactionUploadPreviewResponse]"},"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":[]}]}