{"openapi":"3.1.0","info":{"title":"POST /api/v1/inventory/production/runs/{run_id}/cancel","version":"1.0.0","description":"Cancel production run"},"servers":[{"url":"https://api.ondayzero.com","description":"Production"}],"paths":{"/api/v1/inventory/production/runs/{run_id}/cancel":{"post":{"tags":["inventory:production"],"summary":"Cancel production run","description":"Cancel a run. A draft run only changes status. A completed run is undone exactly: its on-hand movements are reversed, consumed cost lots get their units back, its output lots are removed and its production transfer entry is reversed (dated reversal_date, default today). Refused with nothing changed when goods the run made were already sold, used or moved (VALIDATION_892) or the run was completed before completions were recorded (VALIDATION_893). A cancelled run can be completed again.","operationId":"cancel_run","parameters":[{"name":"run_id","in":"path","required":true,"schema":{"type":"string","title":"Run Id"}},{"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":{"content":{"application/json":{"schema":{"anyOf":[{"$ref":"#/components/schemas/RunCancelRequest"},{"type":"null"}],"title":"Payload"}}}},"responses":{"201":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope_RunCancelResponse_"}}}},"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"}}}},"404":{"description":"Not Found - Resource does not exist","content":{"application/json":{"example":{"error":"not_found","message":"Resource not found","code":"NOT_FOUND_001","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"}}}},"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":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"error":"unauthorized","message":"Authentication required","code":"AUTH_001","request_id":"3f0e7c2a-9b4d-4e1a-8c6f-2d5b7a1e9c30"}}}},"403":{"description":"Forbidden - Insufficient permissions","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"error":"forbidden","message":"You don't have permission to access this resource","code":"AUTH_002","request_id":"3f0e7c2a-9b4d-4e1a-8c6f-2d5b7a1e9c30"}}}}},"x-fastapi-operation-id":"cancel_run_api_v1_inventory_production_runs__run_id__cancel_post"}}},"components":{"schemas":{"CostBreakdown":{"properties":{"materials_by_category":{"additionalProperties":{"type":"integer"},"type":"object","title":"Materials By Category","description":"Cost per category in cents."},"processing_steps_by_type":{"additionalProperties":{"type":"integer"},"type":"object","title":"Processing Steps By Type","description":"Cost per step_type in cents."},"material_line_items":{"items":{"additionalProperties":true,"type":"object"},"type":"array","title":"Material Line Items"},"step_line_items":{"items":{"additionalProperties":true,"type":"object"},"type":"array","title":"Step Line Items"},"total_cost":{"type":"integer","title":"Total Cost","default":0},"cost_per_unit":{"type":"integer","title":"Cost Per Unit","default":0},"sales_potential":{"type":"integer","title":"Sales Potential","default":0},"gross_profit":{"type":"integer","title":"Gross Profit","default":0},"gross_margin_pct":{"type":"number","title":"Gross Margin Pct","default":0.0},"total_weight":{"type":"number","title":"Total Weight","default":0.0},"total_weight_unit":{"type":"string","title":"Total Weight Unit","default":""}},"type":"object","title":"CostBreakdown","description":"Structured cost breakdown returned by the calculation engine."},"RunCancelRequest":{"properties":{"reversal_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Reversal Date","description":"Date of the entry that reverses the production transfer, when one was posted (YYYY-MM-DD); defaults to today."}},"type":"object","title":"RunCancelRequest","description":"Optional details for cancelling a run; every field may be omitted."},"RunCancelResponse":{"properties":{"id":{"type":"string","title":"Id"},"business_id":{"type":"string","title":"Business Id"},"recipe_id":{"type":"string","title":"Recipe Id"},"name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Name"},"total_units":{"type":"integer","title":"Total Units"},"unit_sale_price":{"type":"integer","title":"Unit Sale Price"},"status":{"type":"string","title":"Status"},"cost_snapshot":{"anyOf":[{"$ref":"#/components/schemas/CostBreakdown"},{"type":"null"}]},"completed_on":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Completed On"},"tolling_cents":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Tolling Cents"},"tolling_vendor_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Tolling Vendor Id"},"tolling_bill_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Tolling Bill Id"},"created_at":{"type":"string","format":"date-time","title":"Created At"},"updated_at":{"type":"string","format":"date-time","title":"Updated At"},"reversal_journal_entry_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Reversal Journal Entry Id","description":"Entry reversing the production transfer, when one was posted."},"stock_rows_reversed":{"type":"integer","title":"Stock Rows Reversed","description":"On-hand movements of the completion that were undone.","default":0}},"type":"object","required":["id","business_id","recipe_id","total_units","unit_sale_price","status","created_at","updated_at"],"title":"RunCancelResponse","description":"A cancelled run plus the entry that reversed its production transfer."},"SuccessEnvelope_RunCancelResponse_":{"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/RunCancelResponse"},{"type":"null"}]}},"additionalProperties":true,"type":"object","title":"SuccessEnvelope[RunCancelResponse]"},"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":[]}]}