{"openapi":"3.1.0","info":{"title":"POST /api/v1/o2c/deals","version":"1.0.0","description":"Create a deal"},"servers":[{"url":"https://api.ondayzero.com","description":"Production"}],"paths":{"/api/v1/o2c/deals":{"post":{"tags":["deals"],"summary":"Create a deal","description":"Create a pipeline deal. Provide either `prospect_name` (before a real customer record exists) or `customer_id` (an expansion deal on an existing customer). `stage` defaults to `prospecting`.","operationId":"create_deal","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/DealCreate"}}}},"responses":{"201":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope_DealResponse_"}}}},"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/invalid token 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"}}}},"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"}}}}},"x-fastapi-operation-id":"create_deal_api_v1_o2c_deals_post"}}},"components":{"schemas":{"DealCreate":{"properties":{"prospect_name":{"anyOf":[{"type":"string","maxLength":255},{"type":"null"}],"title":"Prospect Name","description":"Free-text prospect/company name, used before a real customer record exists. Required unless customer_id is set."},"customer_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Customer Id","description":"Existing customer this deal is for (expansion deal). Required unless prospect_name is set."},"name":{"anyOf":[{"type":"string","maxLength":255},{"type":"null"}],"title":"Name","description":"Deal name. Defaults to the prospect/customer name."},"contact_name":{"anyOf":[{"type":"string","maxLength":255},{"type":"null"}],"title":"Contact Name","description":"Sales contact."},"contact_email":{"anyOf":[{"type":"string","maxLength":255},{"type":"null"}],"title":"Contact Email","description":"Sales contact email. Never written to the customer record -- may later become the order signer."},"source":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Source","description":"One of ['event', 'expansion', 'inbound', 'other', 'outbound', 'partner', 'referral']."},"stage":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Stage","description":"One of ['closed_lost', 'closed_won', 'negotiation', 'proposal', 'prospecting', 'qualified']. Defaults to 'prospecting'."},"is_expansion":{"type":"boolean","title":"Is Expansion","description":"True if this is expansion revenue on an existing customer.","default":false},"expected_value_cents":{"type":"integer","minimum":0.0,"title":"Expected Value Cents","description":"Estimated deal value in cents.","default":0},"expected_hours":{"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":"Expected Hours","description":"Estimated hours."},"expected_term_months":{"anyOf":[{"type":"integer","minimum":1.0},{"type":"null"}],"title":"Expected Term Months","description":"Estimated contract term in months."},"expected_start_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Expected Start Date","description":"Estimated start date."},"expected_close_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Expected Close Date","description":"Estimated close date."},"notes":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Notes","description":"Free-text notes."},"owner_name":{"anyOf":[{"type":"string","maxLength":255},{"type":"null"}],"title":"Owner Name","description":"Sales rep / deal owner. Free text (reps are often not DayZero users); the pipeline's owner filter matches on it exactly."},"deal_type":{"anyOf":[{"type":"string","maxLength":60},{"type":"null"}],"title":"Deal Type","description":"Business-defined deal category, e.g. 'Subcontractor', 'EPC', 'Developer'. Free text -- every business slices deals differently."},"revenue_type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Revenue Type","description":"How the money arrives: 'recurring' (monthly) or 'one_time' (prepaid up front)."}},"type":"object","title":"DealCreate","description":"Request schema for creating a pipeline deal.\n\nEither ``prospect_name`` or ``customer_id`` is required (mirrors the\n``deals`` table: early-stage deals track a free-text prospect until a\nreal ``customers`` row exists). ``stage`` defaults to ``prospecting``\nwhen omitted."},"DealResponse":{"properties":{"id":{"type":"string","title":"Id"},"business_id":{"type":"string","title":"Business Id"},"number":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Number"},"name":{"type":"string","title":"Name"},"stage":{"type":"string","title":"Stage"},"effective_stage":{"type":"string","title":"Effective Stage","description":"The stage the deal should be treated as: deal.stage, or the linked order's status once order_id is set."},"prospect_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Prospect Name"},"customer_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Customer Id"},"customer_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Customer Name"},"project_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Project Id"},"project_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Project Name"},"contact_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Contact Name"},"contact_email":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Contact Email"},"owner_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Owner Name"},"deal_type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Deal Type"},"revenue_type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Revenue Type"},"source":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Source"},"is_expansion":{"type":"boolean","title":"Is Expansion","default":false},"expected_value_cents":{"type":"integer","title":"Expected Value Cents","default":0},"expected_hours":{"anyOf":[{"type":"string","pattern":"^(?!^[-+.]*$)[+-]?0*\\d*\\.?\\d*$"},{"type":"null"}],"title":"Expected Hours"},"expected_term_months":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Expected Term Months"},"expected_start_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Expected Start Date"},"expected_close_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Expected Close Date"},"order_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Order Id"},"lost_reason":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Lost Reason"},"notes":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Notes"},"stage_changed_at":{"type":"string","format":"date-time","title":"Stage Changed At"},"days_in_stage":{"type":"integer","title":"Days In Stage","default":0},"is_stalled":{"type":"boolean","title":"Is Stalled","default":false},"is_open":{"type":"boolean","title":"Is Open","default":false},"is_closed":{"type":"boolean","title":"Is Closed","default":false},"is_won":{"type":"boolean","title":"Is Won","default":false},"is_lost":{"type":"boolean","title":"Is Lost","default":false},"is_converted":{"type":"boolean","title":"Is Converted","default":false},"created_at":{"type":"string","format":"date-time","title":"Created At"},"updated_at":{"type":"string","format":"date-time","title":"Updated At"}},"type":"object","required":["id","business_id","name","stage","effective_stage","stage_changed_at","created_at","updated_at"],"title":"DealResponse","description":"Response schema for a deal."},"SuccessEnvelope_DealResponse_":{"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/DealResponse"},{"type":"null"}]}},"additionalProperties":true,"type":"object","title":"SuccessEnvelope[DealResponse]"},"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":[]}]}