{"openapi":"3.1.0","info":{"title":"POST /api/v1/inventory/production/runs/{run_id}/complete","version":"1.0.0","description":"Complete production run"},"servers":[{"url":"https://api.ondayzero.com","description":"Production"}],"paths":{"/api/v1/inventory/production/runs/{run_id}/complete":{"post":{"tags":["inventory:production"],"summary":"Complete production run","description":"Mark a run as completed: consume material cost lots and create output lots, take the components out of on-hand stock and add the finished goods, at location_id or the business's default location. Refused (VALIDATION_890, nothing moved) when a stock-tracked component's available stock there is short. A component with no stock history, or a stock item whose recipe unit differs from its stock unit, keeps its on-hand and is listed in warnings. When inventory ledgers are mapped (PUT /inventory/ledger-settings) it also posts one production transfer entry dated completion_date: Cr raw materials / packaging for the cost consumed, Cr accrued inventory for processing-step cost, Cr accrued inventory (or AP with tolling_bill_id) for tolling_cents, Dr finished goods for the total. Without the mapping journal_entry is null and reason says why.","operationId":"complete_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/RunCompleteRequest"},{"type":"null"}],"title":"Payload"}}}},"responses":{"201":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope_RunCompleteResponse_"}}}},"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":"complete_run_api_v1_inventory_production_runs__run_id__complete_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."},"JournalLinePlan":{"properties":{"ledger_id":{"type":"string","title":"Ledger Id"},"debit_credit":{"type":"string","enum":["debit","credit"],"title":"Debit Credit"},"amount":{"type":"integer","title":"Amount","description":"Cents"},"description":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Description"}},"type":"object","required":["ledger_id","debit_credit","amount"],"title":"JournalLinePlan","description":"One line a production transfer or count posting writes (or would)."},"ProductionJournalEntrySummary":{"properties":{"id":{"type":"string","title":"Id"},"entry_number":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Entry Number"},"date":{"type":"string","format":"date","title":"Date"},"lines":{"items":{"$ref":"#/components/schemas/JournalLinePlan"},"type":"array","title":"Lines"}},"type":"object","required":["id","date"],"title":"ProductionJournalEntrySummary"},"RunCompleteRequest":{"properties":{"completion_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Completion Date","description":"Date the production transfer entry is booked on (YYYY-MM-DD); defaults to today."},"tolling_cents":{"anyOf":[{"type":"integer","minimum":0.0},{"type":"null"}],"title":"Tolling Cents","description":"Co-manufacturer conversion cost to capitalise into finished goods, in cents. Credits Accrued Inventory Liability, or Accounts Payable when tolling_bill_id is given."},"tolling_vendor_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Tolling Vendor Id","description":"Co-manufacturer vendor id (defaults to the bill's vendor)."},"tolling_bill_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Tolling Bill Id","description":"Bill that carries the tolling charge, if already entered."},"location_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Location Id","description":"Location the run takes components from and puts finished goods into; defaults to the business's default location."}},"type":"object","title":"RunCompleteRequest","description":"Optional details for completing a run; every field may be omitted."},"RunCompleteResponse":{"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"},"journal_entry":{"anyOf":[{"$ref":"#/components/schemas/ProductionJournalEntrySummary"},{"type":"null"}]},"reason":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Reason","description":"Why no entry was posted, when journal_entry is null."},"location_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Location Id","description":"Location whose on-hand stock the run moved."},"warnings":{"items":{"type":"string"},"type":"array","title":"Warnings","description":"Stock items whose on-hand was left unchanged, and why (for example a recipe unit that differs from the item's stock unit)."}},"type":"object","required":["id","business_id","recipe_id","total_units","unit_sale_price","status","created_at","updated_at"],"title":"RunCompleteResponse","description":"A completed run plus the production transfer entry it posted."},"SuccessEnvelope_RunCompleteResponse_":{"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/RunCompleteResponse"},{"type":"null"}]}},"additionalProperties":true,"type":"object","title":"SuccessEnvelope[RunCompleteResponse]"},"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":[]}]}