{"openapi":"3.1.0","info":{"title":"GET /api/v1/invoices/collections","version":"1.0.0","description":"AR collections dashboard"},"servers":[{"url":"https://api.ondayzero.com","description":"Production"}],"paths":{"/api/v1/invoices/collections":{"get":{"tags":["invoices"],"summary":"AR collections dashboard","description":"Returns overdue invoices plus AR collection workflow run history and recorded collection reminder emails when present in the database.","operationId":"get_invoice_collections","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"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope_InvoiceCollectionsResponse_"}}}},"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":"get_invoice_collections_api_v1_invoices_collections_get"}}},"components":{"schemas":{"CollectionOverdueInvoice":{"properties":{"id":{"type":"string","title":"Id"},"invoice_number":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Invoice Number"},"customer_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Customer Id"},"customer_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Customer Name"},"customer_email":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Customer Email"},"status":{"type":"string","title":"Status"},"total":{"type":"integer","title":"Total","description":"Invoice total in cents."},"total_paid":{"type":"integer","title":"Total Paid","description":"Total paid in cents.","default":0},"balance_due":{"type":"integer","title":"Balance Due","description":"Remaining balance in cents."},"due_date":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Due Date"},"days_past_due":{"type":"integer","title":"Days Past Due","description":"Days past the due date."},"suggested_reminder_type":{"type":"string","title":"Suggested Reminder Type","description":"Recommended tone: 'friendly', 'firm', or 'final'."},"reminder_count":{"type":"integer","title":"Reminder Count","description":"Collection reminders already recorded for this invoice.","default":0},"last_reminder_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Last Reminder At","description":"ISO timestamp of the most recent collection reminder."}},"type":"object","required":["id","status","total","balance_due","days_past_due","suggested_reminder_type"],"title":"CollectionOverdueInvoice","description":"An overdue invoice surfaced on the Collections tab."},"CollectionReminderHistoryItem":{"properties":{"id":{"type":"string","title":"Id"},"invoice_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Invoice Id"},"reminder_type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Reminder Type"},"days_overdue":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Days Overdue"},"subject":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Subject"},"recipient_email":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Recipient Email"},"recipient_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Recipient Name"},"processing_status":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Processing Status"},"created_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Created At"}},"type":"object","required":["id"],"title":"CollectionReminderHistoryItem","description":"A collection reminder email stored in the emails table."},"CollectionWorkflowRun":{"properties":{"id":{"type":"string","title":"Id"},"workflow_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Workflow Id"},"status":{"type":"string","title":"Status"},"description":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Description"},"started_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Started At"},"created_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Created At"},"completed_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Completed At"},"total_overdue_invoices":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Total Overdue Invoices"},"total_amount_cents":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Total Amount Cents"},"friendly_count":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Friendly Count"},"firm_count":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Firm Count"},"final_count":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Final Count"},"emails_sent":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Emails Sent"},"error_message":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Error Message"},"message":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Message","description":"User-facing failure summary (mirrors error_message when failed)."}},"type":"object","required":["id","status"],"title":"CollectionWorkflowRun","description":"A recorded AR collection workflow run from the tasks table."},"InvoiceCollectionsResponse":{"properties":{"as_of_date":{"type":"string","title":"As Of Date","description":"Report date in YYYY-MM-DD format."},"workflow_id":{"type":"string","title":"Workflow Id","description":"Deterministic Temporal workflow ID for AR collection runs."},"total_overdue_count":{"type":"integer","title":"Total Overdue Count"},"total_overdue_amount_cents":{"type":"integer","title":"Total Overdue Amount Cents"},"overdue_invoices":{"items":{"$ref":"#/components/schemas/CollectionOverdueInvoice"},"type":"array","title":"Overdue Invoices","description":"Open or partially-paid invoices past their due date."},"latest_workflow":{"anyOf":[{"$ref":"#/components/schemas/CollectionWorkflowRun"},{"type":"null"}],"description":"Most recent AR collection workflow run, if any."},"workflow_history":{"items":{"$ref":"#/components/schemas/CollectionWorkflowRun"},"type":"array","title":"Workflow History","description":"Recent AR collection workflow runs newest first."},"reminder_history":{"items":{"$ref":"#/components/schemas/CollectionReminderHistoryItem"},"type":"array","title":"Reminder History","description":"Collection reminder emails recorded in the system."},"auto_send_reminders":{"type":"boolean","title":"Auto Send Reminders","description":"Whether the weekly collections run emails friendly reminders (1-30 days overdue) to customers on its own. Firm and final notices always wait for a person.","default":false}},"type":"object","required":["as_of_date","workflow_id","total_overdue_count","total_overdue_amount_cents"],"title":"InvoiceCollectionsResponse","description":"Collections dashboard: overdue invoices plus workflow and reminder history."},"SuccessEnvelope_InvoiceCollectionsResponse_":{"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/InvoiceCollectionsResponse"},{"type":"null"}]}},"additionalProperties":true,"type":"object","title":"SuccessEnvelope[InvoiceCollectionsResponse]"},"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":[]}]}