{"openapi":"3.1.0","info":{"title":"POST /api/v1/deferred-revenue/bulk-import","version":"1.0.0","description":"Bulk import deferred revenue schedules"},"servers":[{"url":"https://api.ondayzero.com","description":"Production"}],"paths":{"/api/v1/deferred-revenue/bulk-import":{"post":{"tags":["deferred-revenue"],"summary":"Bulk import deferred revenue schedules","description":"Preview (dry_run=true) or create (dry_run=false) deferred revenue schedules in bulk from a CSV export or JSON rows.","operationId":"bulk_import_deferrals","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/BulkDeferralImportRequest"}}}},"responses":{"201":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope_BulkDeferralImportResponse_"}}}},"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_import_deferrals_api_v1_deferred_revenue_bulk_import_post"}}},"components":{"schemas":{"BulkDeferralImportRequest":{"properties":{"csv_text":{"anyOf":[{"type":"string","maxLength":2000000},{"type":"null"}],"title":"Csv Text","description":"CSV with header row (Invoice #, Start Date, Periods, Deferred Amount, ...)"},"rows":{"anyOf":[{"items":{"$ref":"#/components/schemas/BulkDeferralRowInput"},"type":"array","maxItems":500},{"type":"null"}],"title":"Rows","description":"Structured schedule rows (send csv_text or rows, not both)"},"dry_run":{"type":"boolean","title":"Dry Run","description":"When true, validates and previews every row without posting JEs.","default":true}},"type":"object","title":"BulkDeferralImportRequest","description":"Preview or commit a batch of deferred revenue schedules from CSV or rows."},"BulkDeferralImportResponse":{"properties":{"dry_run":{"type":"boolean","title":"Dry Run"},"total_rows":{"type":"integer","title":"Total Rows"},"ready_count":{"type":"integer","title":"Ready Count"},"created_count":{"type":"integer","title":"Created Count"},"skipped_count":{"type":"integer","title":"Skipped Count"},"error_count":{"type":"integer","title":"Error Count"},"total_deferred_cents":{"type":"integer","title":"Total Deferred Cents"},"results":{"items":{"$ref":"#/components/schemas/BulkDeferralRowResult"},"type":"array","title":"Results"}},"type":"object","required":["dry_run","total_rows","ready_count","created_count","skipped_count","error_count","total_deferred_cents","results"],"title":"BulkDeferralImportResponse","description":"Summary and per-row outcomes for bulk deferred revenue schedule import."},"BulkDeferralRowInput":{"properties":{"invoice_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Invoice Id","description":"DayZero invoice UUID (provide invoice_id or invoice_number)"},"invoice_number":{"anyOf":[{"type":"string","maxLength":120},{"type":"null"}],"title":"Invoice Number","description":"Invoice number (matched against the business's invoices)"},"deferred_amount_cents":{"anyOf":[{"type":"integer","exclusiveMinimum":0.0},{"type":"null"}],"title":"Deferred Amount Cents","description":"Amount to defer in cents (defaults to full invoice revenue)"},"unit":{"$ref":"#/components/schemas/DeferralUnitEnum","default":"months"},"method":{"$ref":"#/components/schemas/DeferralMethodEnum","default":"straight_line"},"period_count":{"type":"integer","maximum":600.0,"exclusiveMinimum":0.0,"title":"Period Count"},"total_units":{"anyOf":[{"type":"number","exclusiveMinimum":0.0},{"type":"string"},{"type":"null"}],"title":"Total Units"},"start_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Start Date"},"revenue_ledger_name":{"anyOf":[{"type":"string","maxLength":255},{"type":"null"}],"title":"Revenue Ledger Name"},"notes":{"anyOf":[{"type":"string","maxLength":2000},{"type":"null"}],"title":"Notes"}},"type":"object","required":["period_count"],"title":"BulkDeferralRowInput","description":"One invoice schedule row in a bulk deferred revenue import."},"BulkDeferralRowResult":{"properties":{"row":{"type":"integer","title":"Row"},"invoice_number":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Invoice Number"},"invoice_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Invoice Id"},"status":{"type":"string","enum":["ready","created","skipped","error"],"title":"Status"},"deferred_amount_cents":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Deferred Amount Cents"},"period_count":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Period Count"},"start_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Start Date"},"deferral_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Deferral Id"},"message":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Message"}},"type":"object","required":["row","status"],"title":"BulkDeferralRowResult","description":"Outcome for one row in a bulk deferred revenue import."},"DeferralMethodEnum":{"type":"string","enum":["straight_line","custom"],"title":"DeferralMethodEnum","description":"How each period's numerator is filled in."},"DeferralUnitEnum":{"type":"string","enum":["months","hours","custom"],"title":"DeferralUnitEnum","description":"Denominator unit the deferral burns down against."},"SuccessEnvelope_BulkDeferralImportResponse_":{"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/BulkDeferralImportResponse"},{"type":"null"}]}},"additionalProperties":true,"type":"object","title":"SuccessEnvelope[BulkDeferralImportResponse]"},"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":[]}]}