{"openapi":"3.1.0","info":{"title":"POST /api/v1/businesses/{business_id}/trial-balance/bridge","version":"1.0.0","description":"Compare another system's trial balance with ours"},"servers":[{"url":"https://api.ondayzero.com","description":"Production"}],"paths":{"/api/v1/businesses/{business_id}/trial-balance/bridge":{"post":{"tags":["businesses"],"summary":"Compare another system's trial balance with ours","description":"Read-only. Matches each external account to a ledger and gives every ledger a verdict: tied, intentional, offsetting_swing or unexplained.","operationId":"compare_trial_balance_bridge","parameters":[{"name":"business_id","in":"path","required":true,"schema":{"type":"string","title":"Business 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/TrialBalanceBridgeRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope_TrialBalanceBridgeResponse_"}}}},"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"}}}},"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":"compare_trial_balance_bridge_api_v1_businesses__business_id__trial_balance_bridge_post"}}},"components":{"schemas":{"BridgeLedgerRow":{"properties":{"ledger_id":{"type":"string","title":"Ledger Id"},"account_number":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Account Number"},"name":{"type":"string","title":"Name"},"type":{"type":"string","title":"Type"},"sort_code":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Sort Code"},"external_accounts":{"items":{"type":"string"},"type":"array","title":"External Accounts"},"matched_by":{"type":"string","enum":["mapping","account_number","name","normalised_name"],"title":"Matched By"},"ours_cents":{"type":"integer","title":"Ours Cents"},"theirs_cents":{"type":"integer","title":"Theirs Cents"},"delta_cents":{"type":"integer","title":"Delta Cents","description":"ours - theirs."},"verdict":{"type":"string","enum":["tied","intentional","offsetting_swing","unexplained"],"title":"Verdict"},"reason":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Reason"},"intentional_amount_cents":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Intentional Amount Cents"},"remaining_delta_cents":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Remaining Delta Cents"},"prior_delta_cents":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Prior Delta Cents"},"swing_net_cents":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Swing Net Cents"}},"type":"object","required":["ledger_id","name","type","external_accounts","matched_by","ours_cents","theirs_cents","delta_cents","verdict"],"title":"BridgeLedgerRow"},"BridgeLedgerWithoutExternal":{"properties":{"ledger_id":{"type":"string","title":"Ledger Id"},"account_number":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Account Number"},"name":{"type":"string","title":"Name"},"type":{"type":"string","title":"Type"},"ours_cents":{"type":"integer","title":"Ours Cents"}},"type":"object","required":["ledger_id","name","type","ours_cents"],"title":"BridgeLedgerWithoutExternal"},"BridgeUnmappedRow":{"properties":{"account":{"type":"string","title":"Account"},"balance_cents":{"type":"integer","title":"Balance Cents"},"reason":{"type":"string","enum":["no_match","ambiguous"],"title":"Reason"},"candidates":{"items":{"additionalProperties":{"type":"string"},"type":"object"},"type":"array","title":"Candidates"}},"type":"object","required":["account","balance_cents","reason"],"title":"BridgeUnmappedRow"},"BridgeVerdictTotals":{"properties":{"count":{"type":"integer","title":"Count"},"ours_cents":{"type":"integer","title":"Ours Cents"},"theirs_cents":{"type":"integer","title":"Theirs Cents"},"delta_cents":{"type":"integer","title":"Delta Cents"}},"type":"object","required":["count","ours_cents","theirs_cents","delta_cents"],"title":"BridgeVerdictTotals"},"ExternalTrialBalanceRow":{"properties":{"account":{"type":"string","title":"Account","description":"Account name or number in the other system."},"account_number":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Account Number"},"balance_cents":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Balance Cents","description":"Debit minus credit. Send this or debit/credit."},"debit_cents":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Debit Cents"},"credit_cents":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Credit Cents"}},"additionalProperties":false,"type":"object","required":["account"],"title":"ExternalTrialBalanceRow","description":"One account of the other system's trial balance, debit-positive cents."},"IntentionalDifference":{"properties":{"ledger_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Ledger Id"},"account_number":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Account Number"},"reason":{"type":"string","title":"Reason","description":"Why the two systems differ here by design."},"amount_cents":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Amount Cents","description":"Part of the difference (ours - theirs, signed) the decision explains; omit when it explains all of it."}},"additionalProperties":false,"type":"object","required":["reason"],"title":"IntentionalDifference"},"SuccessEnvelope_TrialBalanceBridgeResponse_":{"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/TrialBalanceBridgeResponse"},{"type":"null"}]}},"additionalProperties":true,"type":"object","title":"SuccessEnvelope[TrialBalanceBridgeResponse]"},"TrialBalanceBridgeRequest":{"properties":{"as_of_date":{"type":"string","title":"As Of Date","description":"Date of the external trial balance."},"rows":{"anyOf":[{"items":{"$ref":"#/components/schemas/ExternalTrialBalanceRow"},"type":"array"},{"type":"null"}],"title":"Rows","description":"Up to 1,000 rows. Send rows or csv_text."},"csv_text":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Csv Text","description":"CSV with a header: account, optional account_number, then balance_cents or debit_cents and credit_cents."},"mapping":{"anyOf":[{"additionalProperties":{"type":"string"},"type":"object"},{"type":"null"}],"title":"Mapping","description":"External account -> our ledger_id or account_number."},"intentional":{"anyOf":[{"items":{"$ref":"#/components/schemas/IntentionalDifference"},"type":"array"},{"type":"null"}],"title":"Intentional"},"tolerance_cents":{"type":"integer","maximum":1000000.0,"minimum":0.0,"title":"Tolerance Cents","default":100},"prior_rows":{"anyOf":[{"items":{"$ref":"#/components/schemas/ExternalTrialBalanceRow"},"type":"array"},{"type":"null"}],"title":"Prior Rows","description":"The same trial balance at prior_as_of, for cut-off swings."},"prior_as_of":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Prior As Of"},"basis":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Basis","description":"`accrual` or `cash`."}},"additionalProperties":false,"type":"object","required":["as_of_date"],"title":"TrialBalanceBridgeRequest"},"TrialBalanceBridgeResponse":{"properties":{"as_of_date":{"type":"string","title":"As Of Date"},"prior_as_of":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Prior As Of"},"basis":{"anyOf":[{"type":"string","enum":["accrual","cash"]},{"type":"null"}],"title":"Basis"},"tolerance_cents":{"type":"integer","title":"Tolerance Cents"},"row_count":{"type":"integer","title":"Row Count"},"ledgers":{"items":{"$ref":"#/components/schemas/BridgeLedgerRow"},"type":"array","title":"Ledgers"},"totals":{"additionalProperties":{"$ref":"#/components/schemas/BridgeVerdictTotals"},"type":"object","title":"Totals"},"unmapped":{"items":{"$ref":"#/components/schemas/BridgeUnmappedRow"},"type":"array","title":"Unmapped"},"ledgers_without_external":{"items":{"$ref":"#/components/schemas/BridgeLedgerWithoutExternal"},"type":"array","title":"Ledgers Without External"}},"type":"object","required":["as_of_date","tolerance_cents","row_count","ledgers","totals","unmapped","ledgers_without_external"],"title":"TrialBalanceBridgeResponse"},"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":[]}]}