{"openapi":"3.1.0","info":{"title":"GET /api/v1/credit/import-batches/{staging_id}/history-report","version":"1.0.0","description":"The report of a history file's last run"},"servers":[{"url":"https://api.ondayzero.com","description":"Production"}],"paths":{"/api/v1/credit/import-batches/{staging_id}/history-report":{"get":{"tags":["credit"],"summary":"The report of a history file's last run","description":"The last dry run or apply of a staged payments or statements file: per line what was attached, duplicated and rejected (every rejected row with its reason), the control totals against what attached, and the warnings. Open to any token on a sandbox business; on a live business an operator action (an API token receives `403`).","operationId":"credit_history_get_report","parameters":[{"name":"staging_id","in":"path","required":true,"schema":{"type":"string","description":"The staged history file (its batch id).","title":"Staging Id"},"description":"The staged history file (its batch 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"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope_HistoryImportResponse_"}}}},"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":"credit_history_get_report_api_v1_credit_import_batches__staging_id__history_report_get"}}},"components":{"schemas":{"HistoryExpectedTotals":{"properties":{"count":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Count","description":"Expected count."},"amount_cents":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Amount Cents","description":"Expected amount."}},"type":"object","title":"HistoryExpectedTotals","description":"The control totals the run was given."},"HistoryImportResponse":{"properties":{"staging_id":{"type":"string","title":"Staging Id","description":"The batch."},"program_id":{"type":"string","title":"Program Id","description":"The program."},"kind":{"type":"string","enum":["payments","statements"],"title":"Kind","description":"`payments` or `statements`."},"filename":{"type":"string","title":"Filename","description":"The file's name as uploaded."},"sha256":{"type":"string","title":"Sha256","description":"SHA-256 of the file."},"dry_run":{"type":"boolean","title":"Dry Run","description":"Nothing was meant to be written."},"applied":{"type":"boolean","title":"Applied","description":"Every line was attached together. False on a dry run, and when a control total did not match: then nothing was attached."},"run_at":{"type":"string","format":"date-time","title":"Run At","description":"When the run happened (UTC)."},"run_by":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Run By","description":"Who ran it."},"attached":{"type":"integer","title":"Attached","description":"Payments or statements attached.","default":0},"duplicates":{"type":"integer","title":"Duplicates","description":"Already attached: loaded once.","default":0},"rejected":{"type":"integer","title":"Rejected","description":"Rows not attached, over the file.","default":0},"derived":{"type":"integer","title":"Derived","description":"Payments attached with a derived split.","default":0},"totals":{"$ref":"#/components/schemas/HistoryTotals","description":"What was attached (or would be): checked against `expected`."},"expected":{"$ref":"#/components/schemas/HistoryExpectedTotals","description":"The control totals the run was given, from the partner's book."},"mismatches":{"items":{"type":"string"},"type":"array","title":"Mismatches","description":"Each control total that did not match, in words. On an apply they refused, a last entry says nothing was attached."},"lines":{"items":{"$ref":"#/components/schemas/HistoryLineResult"},"type":"array","title":"Lines","description":"What the run did on each line."},"rejections":{"items":{"$ref":"#/components/schemas/HistoryRowRejection"},"type":"array","title":"Rejections","description":"Every row not attached, in file order."},"warnings":{"items":{"$ref":"#/components/schemas/ImportWarning"},"type":"array","title":"Warnings","description":"Things to read: `history_incomplete` (a line's historical payments do not account for everything its imported loans carried as paid), `figures_only` (a statement attached without its document)."},"warning_count":{"type":"integer","title":"Warning Count","description":"Every warning of the run.","default":0},"dry_run_token":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Dry Run Token","description":"On a dry run: send it on the apply as `dry_run_token` to attach exactly what this dry run checked. Null on an apply."}},"type":"object","required":["staging_id","program_id","kind","filename","sha256","dry_run","applied","run_at"],"title":"HistoryImportResponse","description":"The outcome of a dry run or apply of a payments or statements file.\n\nKept on the batch as its report: ``GET\n/credit/import-batches/{id}/history-report``."},"HistoryLineResult":{"properties":{"line_key":{"type":"string","title":"Line Key","description":"The line key."},"credit_line_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Credit Line Id","description":"The line; null when the program has none."},"attached":{"type":"integer","title":"Attached","description":"Payments or statements attached.","default":0},"duplicates":{"type":"integer","title":"Duplicates","description":"Already attached to the line: loaded once.","default":0},"rejected":{"type":"integer","title":"Rejected","description":"Rows that were not attached.","default":0},"derived":{"type":"integer","title":"Derived","description":"Payments: attached with a split DayZero derived (D-10, D-11, D-58).","default":0},"amount_cents":{"type":"integer","title":"Amount Cents","description":"Payments: amounts attached. Statements: their statement balances.","default":0},"paid_at_import_cents":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Paid At Import Cents","description":"Payments: what the line's imported loans carried as paid before the import, every bucket."},"history_cents":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"History Cents","description":"Payments: what the line's historical payments account for of that, this file's included. Equal when the history is complete."},"error":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Error","description":"Why no row of the line was attached."}},"type":"object","required":["line_key"],"title":"HistoryLineResult","description":"What the run did on one line."},"HistoryRowRejection":{"properties":{"row_number":{"type":"integer","title":"Row Number","description":"Position in the file, from 1."},"line_key":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Line Key","description":"The row's line key."},"reference":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Reference","description":"The partner's payment or statement id."},"reason":{"type":"string","title":"Reason","description":"Why it was not attached."}},"type":"object","required":["row_number","reason"],"title":"HistoryRowRejection","description":"A row (or a payment's rows) that was not attached, and why."},"HistoryTotals":{"properties":{"count":{"type":"integer","title":"Count","description":"Attached plus duplicates.","default":0},"amount_cents":{"type":"integer","title":"Amount Cents","description":"Payments: amounts. Statements: statement balances.","default":0}},"type":"object","title":"HistoryTotals","description":"Count and money over what was attached (or would be)."},"ImportWarning":{"properties":{"code":{"type":"string","title":"Code","description":"`no_interest_ceiling`: the program has no ceiling on a loan's interest, and the ceiling is frozen onto each loan when it is created, so these loans stay uncapped for good. `repeats_id_on_other_line`: the row loaded although its transaction id is already on another line."},"message":{"type":"string","title":"Message","description":"What it means and what to do, in words."},"row_number":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Row Number","description":"Position in the file, from 1; null for the run."},"line_key":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Line Key","description":"The row's line key."},"external_settlement_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"External Settlement Id","description":"The row's issuer transaction id."}},"type":"object","required":["code","message"],"title":"ImportWarning","description":"Something the operator should read before applying; the run did not stop."},"SuccessEnvelope_HistoryImportResponse_":{"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/HistoryImportResponse"},{"type":"null"}]}},"additionalProperties":true,"type":"object","title":"SuccessEnvelope[HistoryImportResponse]"},"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":[]}]}