{"openapi":"3.1.0","info":{"title":"PATCH /api/v1/contracts/{contract_id}","version":"1.0.0","description":"Edit contract"},"servers":[{"url":"https://api.ondayzero.com","description":"Production"}],"paths":{"/api/v1/contracts/{contract_id}":{"patch":{"tags":["contracts"],"summary":"Edit contract","description":"Edit a contract's descriptive/schedule fields (number, first invoice date, estimated end date). Running tallies (billed/recognized/value) are maintained by the billing engine and cannot be edited.","operationId":"update_contract_api_v1_contracts__contract_id__patch","parameters":[{"name":"contract_id","in":"path","required":true,"schema":{"type":"string","title":"Contract 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":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ContractUpdate"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope_ContractResponse_"}}}},"400":{"description":"Bad Request - Invalid input","content":{"application/json":{"example":{"detail":"Invalid request parameters"}}}},"401":{"description":"Unauthorized - Authentication required","content":{"application/json":{"example":{"detail":"Not authenticated"}}}},"403":{"description":"Forbidden - Insufficient permissions","content":{"application/json":{"example":{"detail":"Not enough permissions"}}}},"404":{"description":"Not Found - Resource does not exist","content":{"application/json":{"example":{"detail":"Resource not found"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}},"components":{"schemas":{"ContractLineItemUpdate":{"properties":{"id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Id","description":"Order line to edit; omit to append a new line."},"catalog_item_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Catalog Item Id","description":"Catalog item for a new line (append only, optional)."},"description":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Description","description":"Line description (explicit null clears it on edit)."},"qty":{"anyOf":[{"type":"number","minimum":0.0},{"type":"string","pattern":"^(?!^[-+.]*$)[+-]?0*(?:\\d{0,14}|(?=[\\d.]{1,17}0*$)\\d{0,14}\\.\\d{0,2}0*$)"},{"type":"null"}],"title":"Qty","description":"Ordered quantity / hours (up to 2 decimal places)."},"unit_price_cents":{"anyOf":[{"type":"number","minimum":0.0},{"type":"string","pattern":"^(?!^[-+.]*$)[+-]?0*\\d*\\.?\\d{0,2}0*$"},{"type":"null"}],"title":"Unit Price Cents","description":"Unit price in cents; up to 2 decimal places of a cent for sub-cent rates (e.g. 5.25 = $0.0525)."},"billing_rule":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Billing Rule","description":"New line only: flat, per_unit, recurring, usage_metered, or prepaid_block (defaults to flat)."},"billing_timing":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Billing Timing","description":"New recurring line only: each_period, first_upfront, all_upfront."},"ramp_schedule":{"anyOf":[{"additionalProperties":true,"type":"object"},{"type":"null"}],"title":"Ramp Schedule","description":"New recurring line only: pre-agreed step schedule."}},"type":"object","title":"ContractLineItemUpdate","description":"Edit — or append — one line of the contract's originating order.\n\nWhen ``id`` is set it must be a line of the contract's own order and the\nrow is edited in place: ``description`` is always editable (an explicit\nnull clears it); ``qty`` and ``unit_price_cents`` change the contract's\nvalue, so they are only accepted while no money has moved on the contract\n(nothing billed, nothing recognized, no approved drawdowns) — after that,\nvalue changes must go through a change order. Omitted fields are left\nuntouched.\n\nWhen ``id`` is omitted the row is a NEW line APPENDED to the order\n(``qty`` and ``unit_price_cents`` are then required, and\n``catalog_item_id`` / ``billing_rule`` / ``billing_timing`` /\n``ramp_schedule`` may be supplied). Appending a line changes the contract\nvalue, so it is subject to the same \"no money moved\" guard as a pricing\nedit."},"ContractResponse":{"properties":{"id":{"type":"string","title":"Id"},"business_id":{"type":"string","title":"Business Id"},"order_id":{"type":"string","title":"Order Id"},"project_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Project Id"},"project_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Project Name"},"project_code":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Project Code"},"project_sku":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Project Sku"},"customer_id":{"type":"string","title":"Customer Id"},"customer_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Customer Name"},"number":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Number"},"status":{"type":"string","title":"Status"},"currency":{"type":"string","title":"Currency"},"original_value_cents":{"type":"integer","title":"Original Value Cents","default":0},"current_value_cents":{"type":"integer","title":"Current Value Cents","default":0},"billed_cents":{"type":"integer","title":"Billed Cents","default":0},"recognized_cents":{"type":"integer","title":"Recognized Cents","default":0},"deferred_remaining_cents":{"type":"integer","title":"Deferred Remaining Cents","default":0},"billed_pct":{"type":"number","title":"Billed Pct","default":0.0},"earned_pct":{"type":"number","title":"Earned Pct","default":0.0},"total_contracted_hours":{"type":"string","pattern":"^(?!^[-+.]*$)[+-]?0*\\d*\\.?\\d*$","title":"Total Contracted Hours","default":"0"},"hours_drawn":{"type":"string","pattern":"^(?!^[-+.]*$)[+-]?0*\\d*\\.?\\d*$","title":"Hours Drawn","default":"0"},"hours_remaining":{"type":"string","pattern":"^(?!^[-+.]*$)[+-]?0*\\d*\\.?\\d*$","title":"Hours Remaining","default":"0"},"first_invoice_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"First Invoice Date"},"earliest_linked_invoice_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Earliest Linked Invoice Date"},"end_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"End Date"},"created_at":{"type":"string","format":"date-time","title":"Created At"},"updated_at":{"type":"string","format":"date-time","title":"Updated At"},"can_be_paused":{"type":"boolean","title":"Can Be Paused","default":false},"can_be_resumed":{"type":"boolean","title":"Can Be Resumed","default":false},"can_be_amended":{"type":"boolean","title":"Can Be Amended","default":false}},"type":"object","required":["id","business_id","order_id","customer_id","status","currency","created_at","updated_at"],"title":"ContractResponse","description":"Response schema for a contract."},"ContractUpdate":{"properties":{"number":{"anyOf":[{"type":"string","maxLength":50},{"type":"null"}],"title":"Number","description":"Contract reference number."},"status":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Status","description":"Manual lifecycle change: 'completed' to close the contract, 'on_hold'/'paused' to pause billing, or 'active'/'resume' to resume a paused contract. Routed through the contract's lifecycle guards (can_be_paused / can_be_resumed)."},"first_invoice_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"First Invoice Date","description":"Anchor date for the contract's term clock."},"end_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"End Date","description":"Estimated end of term."},"line_items":{"anyOf":[{"items":{"$ref":"#/components/schemas/ContractLineItemUpdate"},"type":"array"},{"type":"null"}],"title":"Line Items","description":"Per-line edits to the contract's order lines. Lines omitted from the list are left untouched (this is not a wholesale replacement)."}},"type":"object","title":"ContractUpdate","description":"Request to edit a contract's descriptive/schedule fields.\n\nOnly safe fields are editable: the running tallies (billed / recognized /\nvalue) are maintained by the billing engine, and the customer comes from\nthe frozen order. Omitted fields are left untouched; ``first_invoice_date``\nand ``end_date`` accept an explicit null to clear them.\n\n``line_items`` edits the originating order's lines in place (historical\nbackfill): descriptions are always editable; qty/price edits are only\naccepted before any money has moved and recompute the contract's value\nand contracted hours from the updated lines."},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"SuccessEnvelope_ContractResponse_":{"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/ContractResponse"},{"type":"null"}]}},"additionalProperties":true,"type":"object","title":"SuccessEnvelope[ContractResponse]"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"},"input":{"title":"Input"},"ctx":{"type":"object","title":"Context"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}},"securitySchemes":{"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"API Token","description":"API token authentication. Format: `Bearer dz_...`"}}},"security":[{"BearerAuth":[]}]}