{"openapi":"3.1.0","info":{"title":"POST /api/v1/credit/sandbox/scenarios/portfolio-50","version":"1.0.0","description":"Generate a whole sandbox book from a seed"},"servers":[{"url":"https://api.ondayzero.com","description":"Production"}],"paths":{"/api/v1/credit/sandbox/scenarios/portfolio-50":{"post":{"tags":["credit"],"summary":"Generate a whole sandbox book from a seed","description":"Sandbox only. Queues a job that generates `merchants` merchants (default 50) over `months` months (default 6) from `seed` through the real services: lines opened, settlements and refunds ingested, statements closed and interest accrued month by month, payments recorded on time, late and in part, one returned, one dispute, one write-off, and lines at every collections stage. Poll `GET /credit/sandbox/jobs/{id}` until `status` is `succeeded` or `failed`. The same seed, size and `as_of` always give the same book (`result.loan_tape_digest`). Asking again while the seed's job is queued or running returns that job (`created: false`), unless it is `stale` (past its one-hour limit): that job is recorded `failed` and a new one is queued.","operationId":"credit_stage_portfolio_scenario","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/PortfolioScenarioRequest"}}}},"responses":{"202":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope_SandboxJobResponse_"}}}},"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_stage_portfolio_scenario_api_v1_credit_sandbox_scenarios_portfolio_50_post"}}},"components":{"schemas":{"PartnerExportCounts":{"properties":{"lines_created":{"type":"integer","title":"Lines Created","description":"Credit lines opened."},"lines_reused":{"type":"integer","title":"Lines Reused","description":"Merchants that already had a line on the program."},"settlements":{"type":"integer","title":"Settlements","description":"Settlements accepted."},"duplicates":{"type":"integer","title":"Duplicates","description":"Settlements already on the book."},"payments":{"type":"integer","title":"Payments","description":"Payments recorded."},"payments_skipped":{"type":"integer","title":"Payments Skipped","description":"Payments the engine refused; why is in `skipped_payments`.","default":0},"skipped_payments":{"items":{"$ref":"#/components/schemas/PartnerExportSkippedRow"},"type":"array","title":"Skipped Payments","description":"Each refused payment and why."},"opening_loans":{"type":"integer","title":"Opening Loans","description":"Opening loans imported.","default":0},"opening_loans_duplicate":{"type":"integer","title":"Opening Loans Duplicate","description":"Opening loans already on the line.","default":0},"opening_loans_rejected":{"type":"integer","title":"Opening Loans Rejected","description":"Opening loans the import refused; why is in `rejected_opening_loans`.","default":0},"rejected_opening_loans":{"items":{"$ref":"#/components/schemas/PartnerExportSkippedRow"},"type":"array","title":"Rejected Opening Loans","description":"Each refused opening loan and why."},"write_offs":{"type":"integer","title":"Write Offs","description":"Loans written off.","default":0},"write_offs_duplicate":{"type":"integer","title":"Write Offs Duplicate","description":"Loans already written off on that date.","default":0},"write_offs_skipped":{"type":"integer","title":"Write Offs Skipped","description":"Write-offs that could not be applied; why is in `skipped_write_offs`.","default":0},"skipped_write_offs":{"items":{"$ref":"#/components/schemas/PartnerExportSkippedRow"},"type":"array","title":"Skipped Write Offs","description":"Each write-off not applied and why."},"term_warnings":{"items":{"type":"string"},"type":"array","title":"Term Warnings","description":"Reused lines whose terms differ from the file's (the line's kept)."}},"type":"object","required":["lines_created","lines_reused","settlements","duplicates","payments"],"title":"PartnerExportCounts"},"PartnerExportPlan":{"properties":{"merchant_count":{"type":"integer","title":"Merchant Count","description":"Merchants: one credit line each."},"transaction_count":{"type":"integer","title":"Transaction Count","description":"Card transactions to settle."},"payment_count":{"type":"integer","title":"Payment Count","description":"Repayments to record."},"first_day":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"First Day","description":"The earliest transaction or payment date."},"last_day":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Last Day","description":"The latest transaction or payment date."},"as_of":{"type":"string","format":"date","title":"As Of","description":"Month-ends are closed and interest accrued through this date."},"spend_cents":{"type":"integer","title":"Spend Cents","description":"Card spend, refunds excluded."},"refunds_cents":{"type":"integer","title":"Refunds Cents","description":"Refunds, as a positive figure."},"repayments_cents":{"type":"integer","title":"Repayments Cents","description":"Repayments."},"opening_as_of":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Opening As Of","description":"The date the opening loans are imported as at."},"opening_loan_count":{"type":"integer","title":"Opening Loan Count","description":"Opening loans to import (not settled as swipes).","default":0},"opening_principal_cents":{"type":"integer","title":"Opening Principal Cents","description":"Original principal over the opening loans.","default":0},"write_off_count":{"type":"integer","title":"Write Off Count","description":"Write-offs to apply.","default":0},"term_warnings":{"items":{"type":"string"},"type":"array","title":"Term Warnings","description":"Merchants whose existing line's terms differ from the file's. A reused line keeps its own terms."},"merchants":{"items":{"$ref":"#/components/schemas/PartnerExportPlanMerchant"},"type":"array","title":"Merchants","description":"One row per merchant, by external id."},"skipped":{"items":{"type":"string"},"type":"array","title":"Skipped","description":"Why rows were left out, the first 100."},"skipped_total":{"type":"integer","title":"Skipped Total","description":"How many rows were left out.","default":0}},"type":"object","required":["merchant_count","transaction_count","payment_count","as_of","spend_cents","refunds_cents","repayments_cents"],"title":"PartnerExportPlan"},"PartnerExportPlanMerchant":{"properties":{"external_id":{"type":"string","title":"External Id","description":"The merchant's id in the export."},"name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Name","description":"The merchant's name, if given."},"legal_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Legal Name","description":"The legal name the line is opened with (`merchant_legal_name`, else the name)."},"credit_limit_cents":{"type":"integer","title":"Credit Limit Cents","description":"The line's credit limit."},"term_days":{"type":"integer","title":"Term Days","description":"The line's repayment term."},"disbursement_fee_bps":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Disbursement Fee Bps","description":"The line's disbursement fee from the file (0-500 bps). Null: the program's default."},"rate_bps":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Rate Bps","description":"The line's annual rate from the file. Null: the program's default."},"transactions":{"type":"integer","title":"Transactions","description":"Card transactions for this merchant."},"spend_cents":{"type":"integer","title":"Spend Cents","description":"Net card spend (refunds subtracted) for this merchant."},"paid_cents":{"type":"integer","title":"Paid Cents","description":"Repayments for this merchant."},"opening_loans":{"type":"integer","title":"Opening Loans","description":"Opening loans to import.","default":0},"write_offs":{"type":"integer","title":"Write Offs","description":"Write-offs to apply.","default":0},"existing_line_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Existing Line Id","description":"The line this merchant already has on the program, which is reused with its own terms."},"terms_differ":{"items":{"type":"string"},"type":"array","title":"Terms Differ","description":"Where the file's terms differ from the existing line's, which keeps its own: e.g. `disbursement_fee_bps: file 250, line 100`."}},"type":"object","required":["external_id","credit_limit_cents","term_days","transactions","spend_cents","paid_cents"],"title":"PartnerExportPlanMerchant"},"PartnerExportResponse":{"properties":{"dry_run":{"type":"boolean","title":"Dry Run","description":"True when nothing was written."},"applied":{"type":"boolean","title":"Applied","description":"True when the book was seeded."},"plan":{"$ref":"#/components/schemas/PartnerExportPlan","description":"What the files seed, as figures."},"plan_text":{"type":"string","title":"Plan Text","description":"The same plan as the seeder script prints it."},"mapping_source":{"type":"string","title":"Mapping Source","description":"How the field names were chosen: `defaults`, `given` (the `mapping` sent), or `auto` (worked out from the files).","default":"defaults"},"mapping_notes":{"items":{"type":"string"},"type":"array","title":"Mapping Notes","description":"With `mapping: auto`: each field, the column it was read from, how sure the match is and why, and any field no column answered to."},"warnings":{"items":{"type":"string"},"type":"array","title":"Warnings","description":"Values that look like real people's emails or phone numbers, by file, row and attribute (masked). Applying is refused while there are any, unless `allow_unredacted` is sent with a `reason`."},"unredacted_total":{"type":"integer","title":"Unredacted Total","description":"How many un-redacted values were found in all.","default":0},"allow_unredacted":{"type":"boolean","title":"Allow Unredacted","description":"Whether the caller allowed un-redacted data.","default":false},"unredacted_reason":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Unredacted Reason","description":"The reason given for allowing it."},"counts":{"anyOf":[{"$ref":"#/components/schemas/PartnerExportCounts"},{"type":"null"}],"description":"What was written, when `applied`."}},"type":"object","required":["dry_run","applied","plan","plan_text"],"title":"PartnerExportResponse"},"PartnerExportSkippedRow":{"properties":{"external_id":{"type":"string","title":"External Id","description":"The payment id, or the loan's original transaction id."},"merchant_id":{"type":"string","title":"Merchant Id","description":"The merchant's id in the export."},"on":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"On","description":"The payment, origination or write-off date."},"amount_cents":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Amount Cents","description":"The amount, if any."},"reason":{"type":"string","title":"Reason","description":"Why the engine refused it (code: message)."}},"type":"object","required":["external_id","merchant_id","reason"],"title":"PartnerExportSkippedRow"},"PortfolioScenarioLine":{"properties":{"credit_line_id":{"type":"string","title":"Credit Line Id","description":"The line."},"external_line_id":{"type":"string","title":"External Line Id","description":"The line's id, from the seed."},"profile":{"type":"string","title":"Profile","description":"How the merchant behaves: on_time, late, partial, bounced, disputed, notify, suspend_cards, suspend_line or written_off."},"credit_limit_cents":{"type":"integer","title":"Credit Limit Cents","description":"The line's credit limit."},"delinquency_stage":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Delinquency Stage","description":"The collections stage at `as_of`, if any."},"outstanding_cents":{"type":"integer","title":"Outstanding Cents","description":"Total balance at `as_of`."}},"type":"object","required":["credit_line_id","external_line_id","profile","credit_limit_cents","outstanding_cents"],"title":"PortfolioScenarioLine"},"PortfolioScenarioRequest":{"properties":{"seed":{"type":"integer","maximum":2147483647.0,"minimum":0.0,"title":"Seed","description":"The same seed (and `as_of`) always generates the same book.","default":50},"merchants":{"type":"integer","maximum":200.0,"minimum":1.0,"title":"Merchants","description":"How many merchants (lines).","default":50},"months":{"type":"integer","maximum":12.0,"minimum":1.0,"title":"Months","description":"How many months of history.","default":6},"program_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Program Id","description":"A per-transaction program to stage it on. Omitted: a program named for the seed is created (or reused), with a three-stage collections ladder."},"as_of":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"As Of","description":"The last day of the book. Defaults to today (UTC); the history starts `months` calendar months before its month."}},"additionalProperties":false,"type":"object","title":"PortfolioScenarioRequest"},"PortfolioScenarioResponse":{"properties":{"program_id":{"type":"string","title":"Program Id","description":"The program the book is on."},"program_created":{"type":"boolean","title":"Program Created","description":"True when the program was created for this seed."},"seed":{"type":"integer","title":"Seed","description":"The seed."},"start":{"type":"string","format":"date","title":"Start","description":"The first day of the history."},"as_of":{"type":"string","format":"date","title":"As Of","description":"The last day of the history."},"lines_opened":{"type":"integer","title":"Lines Opened","description":"Credit lines opened."},"cards_issued":{"type":"integer","title":"Cards Issued","description":"DayZero-managed cards issued, one per line, when the program issues on the mock issuer (0 on a program that does not).","default":0},"partner_cards_registered":{"type":"integer","title":"Partner Cards Registered","description":"Partner-managed cards registered on some lines as well.","default":0},"settlements":{"type":"integer","title":"Settlements","description":"Card transactions settled."},"refunds":{"type":"integer","title":"Refunds","description":"Of which refunds."},"payments":{"type":"integer","title":"Payments","description":"Payments recorded."},"payments_reversed":{"type":"integer","title":"Payments Reversed","description":"Payments returned (bounced)."},"disputes_opened":{"type":"integer","title":"Disputes Opened","description":"Disputes opened."},"loans_written_off":{"type":"integer","title":"Loans Written Off","description":"Loans written off."},"statements_closed":{"type":"integer","title":"Statements Closed","description":"Statement periods closed."},"collections_stages":{"additionalProperties":{"type":"integer"},"type":"object","title":"Collections Stages","description":"Lines in each collections stage at `as_of`."},"loan_tape_digest":{"type":"string","title":"Loan Tape Digest","description":"SHA-256 of the loan tape at `as_of` without its generated ids. The same seed, merchants, months and `as_of` give the same digest."},"elapsed_ms":{"type":"integer","title":"Elapsed Ms","description":"How long the generation took."},"lines":{"items":{"$ref":"#/components/schemas/PortfolioScenarioLine"},"type":"array","title":"Lines","description":"Every line, in the order opened."}},"type":"object","required":["program_id","program_created","seed","start","as_of","lines_opened","settlements","refunds","payments","payments_reversed","disputes_opened","loans_written_off","statements_closed","loan_tape_digest","elapsed_ms"],"title":"PortfolioScenarioResponse"},"SandboxJobResponse":{"properties":{"id":{"type":"string","title":"Id","description":"The job."},"kind":{"type":"string","enum":["portfolio","partner_export"],"title":"Kind","description":"What the job does: `portfolio` (the portfolio-50 scenario) or `partner_export` (an applied `POST /credit/sandbox/partner-export`)."},"status":{"type":"string","enum":["queued","running","succeeded","failed"],"title":"Status","description":"Poll until `succeeded` or `failed`, or until `stale`."},"stale":{"type":"boolean","title":"Stale","description":"Still `queued` or `running` an hour after it started (or was queued, if it never started): past the job's own time limit, so its worker has stopped and it will not finish. Nothing was written. Stop polling; asking for the same seed again records this job as `failed` and queues a new one.","default":false},"request":{"additionalProperties":true,"type":"object","title":"Request","description":"What was asked for, with `as_of` resolved to a date."},"result":{"anyOf":[{"$ref":"#/components/schemas/PortfolioScenarioResponse"},{"$ref":"#/components/schemas/PartnerExportResponse"},{"type":"null"}],"title":"Result","description":"Once `succeeded`: the book that was generated (`portfolio`), or the seed's plan and `counts` (`partner_export`)."},"error":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Error","description":"Why it failed (an error code and message when it has one)."},"created_at":{"type":"string","format":"date-time","title":"Created At","description":"When the job was queued (UTC)."},"started_at":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}],"title":"Started At","description":"When it started running (UTC)."},"finished_at":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}],"title":"Finished At","description":"When it succeeded or failed (UTC)."},"created":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Created","description":"On the POST: true when this request queued the job, false when it returned the seed's job that was already queued or running. Absent when the job is read back."}},"type":"object","required":["id","kind","status","request","created_at"],"title":"SandboxJobResponse"},"SuccessEnvelope_SandboxJobResponse_":{"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/SandboxJobResponse"},{"type":"null"}]}},"additionalProperties":true,"type":"object","title":"SuccessEnvelope[SandboxJobResponse]"},"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":[]}]}