# POST /api/v1/credit/lines/{credit_line_id}/loans/import

> Import existing loans onto a line

- **Tag:** credit
- **Operation ID:** `import_loans`

## Description

Launch with live cards and open loans (D-29): loads loans that already exist on the partner's previous system with their paid buckets and interest to date, keyed by the original issuer transaction id so attribution survives the migration (D-33). Idempotent on that id; one bad row is rejected without sinking the batch. Daily accrual resumes from the day after `accrued_through`.

## Authentication

Bearer token in `Authorization` header.
Required header: `x-business-id: <business uuid>`.

## Parameters

- `credit_line_id` (path, string, required)

## Request body

Schema: `LoanImportRequest`

- `as_of` (string · date) — Status is assessed as at this date.
- `loans` (array · LoanImportItem · required) → `LoanImportItem`
  - `external_settlement_id` (string · required) — Original issuer transaction id. The idempotency key.
  - `originated_on` (string · date · required)
  - `principal_cents` (integer · required)
  - `disbursement_fee_cents` (integer) — Defaults to the line's fee rate on the principal.
  - `term_days` (integer) — Defaults to the line's term.
  - `due_date` (string · date) — Defaults to originated_on + term.
  - `rate_bps` (integer)
  - `merchant_name` (string)
  - `card_last_four` (string)
  - `description` (string)
  - `principal_paid_cents` (integer)
  - `fee_paid_cents` (integer)
  - `interest_paid_cents` (integer)
  - `credit_applied_cents` (integer)
  - `interest_accrued_cents` (integer) — Interest accrued to date on the old system.
  - `accrued_through` (string · date) — Date the accrued figure is good through. Accrual resumes after it.
  - `written_off` (boolean)
  - `written_off_on` (string · date)
  - `source_system` (string)

## Responses

### 201 — Successful Response

Schema: `SuccessEnvelope_LoanImportResponse_`

- `success` (boolean)
- `message` (string)
- `code` (string)
- `data` (LoanImportResponse)

### 400 — Bad Request - Invalid input

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 401 — Unauthorized - Missing/invalid token or no access to this business

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 403 — Forbidden - Insufficient permissions

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 404 — Not Found - Resource does not exist

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 422 — Validation Error

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

## Code samples

### cURL

```bash
curl -X POST 'https://api.ondayzero.com/api/v1/credit/lines/{credit_line_id}/loans/import' \
  -H 'Authorization: Bearer dz_your_token' \
  -H 'x-business-id: YOUR_BUSINESS_ID' \
  -H 'Content-Type: application/json' \
  -d '{
  "loans": []
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/credit/lines/{credit_line_id}/loans/import', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer dz_your_token',
    'x-business-id': 'YOUR_BUSINESS_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "loans": []
}),
});
const data = await response.json();
```

### Python

```python
import httpx

headers = {
    "Authorization": "Bearer dz_your_token",
    "x-business-id": "YOUR_BUSINESS_ID",
}

payload = {'loans': []}

response = httpx.post("https://api.ondayzero.com/api/v1/credit/lines/{credit_line_id}/loans/import", headers=headers, json=payload)
data = response.json()
```

## See also

- HTML version: https://www.ondayzero.com/docs/reference/credit/import-loans
- OpenAPI slice: https://www.ondayzero.com/docs/reference/credit/import-loans/openapi.json
- Other endpoints in **credit**: https://www.ondayzero.com/docs/reference/credit (markdown bundle: https://www.ondayzero.com/docs/reference/credit.md, OpenAPI: https://www.ondayzero.com/docs/reference/credit/openapi.json)
- Endpoint catalog: https://www.ondayzero.com/docs/reference/index.md
