{"openapi":"3.1.0","info":{"title":"GET /api/v1/loans/subledger","version":"1.0.0","description":"Loan subledger summary grouped by counterparty"},"servers":[{"url":"https://api.ondayzero.com","description":"Production"}],"paths":{"/api/v1/loans/subledger":{"get":{"tags":["loans"],"summary":"Loan subledger summary grouped by counterparty","description":"Business-wide loan subledger grouped by counterparty.\n\n**Query Parameters:**\n- `direction`: Optional filter — `lend` (notes receivable) or `borrow`;\n  any other value is a 400 validation error.\n\n**Returns:** Counterparty groups with per-loan balances, accrued\ninterest, and rolled-up totals.","operationId":"get_loan_subledger_summary","parameters":[{"name":"direction","in":"query","required":false,"schema":{"anyOf":[{"$ref":"#/components/schemas/DebtDirectionEnum"},{"type":"null"}],"description":"Filter by direction: `lend` or `borrow`.","title":"Direction"},"description":"Filter by direction: `lend` or `borrow`."},{"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_LoanSubledgerSummaryResponse_"}}}},"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 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_loan_subledger_summary_api_v1_loans_subledger_get"}}},"components":{"schemas":{"DebtDirectionEnum":{"type":"string","enum":["borrow","lend"],"title":"DebtDirectionEnum","description":"Which side of the loan the business sits on.\n\n* ``borrow`` — the business is the borrower (a loan *to* us). The\n  counterparty is the lender, principal is a liability, and interest\n  is an expense. This is the historical default.\n* ``lend`` — the business is the lender (a loan *from* us, i.e. a\n  note receivable). The counterparty is the borrower, principal is\n  an asset, and interest is income."},"LoanCounterpartyGroup":{"properties":{"counterparty":{"type":"string","title":"Counterparty"},"counterparty_type":{"type":"string","title":"Counterparty Type"},"loan_count":{"type":"integer","title":"Loan Count"},"outstanding_principal_cents":{"type":"integer","title":"Outstanding Principal Cents"},"accrued_interest_cents":{"type":"integer","title":"Accrued Interest Cents"},"total_receivable_cents":{"type":"integer","title":"Total Receivable Cents","description":"Principal + accrued interest still owed on this group."},"loans":{"items":{"$ref":"#/components/schemas/LoanInstrumentBrief"},"type":"array","title":"Loans"}},"type":"object","required":["counterparty","counterparty_type","loan_count","outstanding_principal_cents","accrued_interest_cents","total_receivable_cents","loans"],"title":"LoanCounterpartyGroup","description":"All loans against one counterparty, with rolled-up balances."},"LoanInstrumentBrief":{"properties":{"id":{"type":"string","title":"Id"},"name":{"type":"string","title":"Name"},"counterparty":{"type":"string","title":"Counterparty"},"counterparty_type":{"type":"string","title":"Counterparty Type"},"direction":{"type":"string","title":"Direction"},"debt_type":{"type":"string","title":"Debt Type"},"status":{"type":"string","title":"Status"},"interest_rate_bps":{"type":"integer","title":"Interest Rate Bps"},"original_principal_cents":{"type":"integer","title":"Original Principal Cents"},"current_balance_cents":{"type":"integer","title":"Current Balance Cents"},"accrued_interest_cents":{"type":"integer","title":"Accrued Interest Cents"},"written_off_cents":{"type":"integer","title":"Written Off Cents"},"start_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Start Date"},"maturity_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Maturity Date"},"last_accrual_date":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Last Accrual Date"}},"type":"object","required":["id","name","counterparty","counterparty_type","direction","debt_type","status","interest_rate_bps","original_principal_cents","current_balance_cents","accrued_interest_cents","written_off_cents"],"title":"LoanInstrumentBrief","description":"Loan header shown above a register and inside counterparty groups."},"LoanSubledgerSummaryResponse":{"properties":{"counterparty_count":{"type":"integer","title":"Counterparty Count"},"loan_count":{"type":"integer","title":"Loan Count"},"total_lent_outstanding_cents":{"type":"integer","title":"Total Lent Outstanding Cents"},"total_borrowed_outstanding_cents":{"type":"integer","title":"Total Borrowed Outstanding Cents"},"total_accrued_receivable_cents":{"type":"integer","title":"Total Accrued Receivable Cents"},"total_accrued_payable_cents":{"type":"integer","title":"Total Accrued Payable Cents"},"groups":{"items":{"$ref":"#/components/schemas/LoanCounterpartyGroup"},"type":"array","title":"Groups"}},"type":"object","required":["counterparty_count","loan_count","total_lent_outstanding_cents","total_borrowed_outstanding_cents","total_accrued_receivable_cents","total_accrued_payable_cents","groups"],"title":"LoanSubledgerSummaryResponse","description":"Business-wide loan subledger grouped by counterparty."},"SuccessEnvelope_LoanSubledgerSummaryResponse_":{"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/LoanSubledgerSummaryResponse"},{"type":"null"}]}},"additionalProperties":true,"type":"object","title":"SuccessEnvelope[LoanSubledgerSummaryResponse]"},"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":[]}]}