# POST /api/v1/businesses/{business_id}/cfo-portal/debt-schedule/instruments/{instrument_id}/payment-schedule/generate

> Generate or rebuild a loan's paydown table

- **Tag:** cfo-portal
- **Operation ID:** `cfo_portal_generate_debt_schedule_api_v1_businesses__business_id__cfo_portal_debt_schedule_instruments__instrument_id__payment_schedule_generate_post`

## Description

(Re)generate a loan's paydown table from its terms.

**Request Body:**
- `overwrite_custom`: when true, discard hand-edited rows and rebuild
  the whole table; when false, preserve customized rows.

## Authentication

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

## Parameters

- `business_id` (path, string, required)
- `instrument_id` (path, string, required)

## Request body

Schema: `DebtScheduleGenerateRequest`

- `overwrite_custom` (boolean) — When true, discard existing rows (including user-edited ones) and rebuild the whole schedule from the instrument's terms. When false, regeneration preserves rows the user customized.

## Responses

### 201 — Successful Response

Schema: `SuccessEnvelope_DebtScheduleResponse_`

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

### 400 — Bad Request - Invalid input

### 401 — Unauthorized - Authentication required

### 403 — Forbidden - Insufficient permissions

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

### 422 — Validation Error

Schema: `HTTPValidationError`

- `detail` (array · ValidationError) → `ValidationError`
  - `loc` (array · string | integer · required)
  - `msg` (string · required)
  - `type` (string · required)
  - `input` (object)
  - `ctx` (object)

## Code samples

### cURL

```bash
curl -X POST 'https://api.ondayzero.com/api/v1/businesses/{business_id}/cfo-portal/debt-schedule/instruments/{instrument_id}/payment-schedule/generate' \
  -H 'Authorization: Bearer dz_your_token' \
  -H 'x-business-id: YOUR_BUSINESS_ID' \
  -H 'Content-Type: application/json' \
  -d '{
  "overwrite_custom": false
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/businesses/{business_id}/cfo-portal/debt-schedule/instruments/{instrument_id}/payment-schedule/generate', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer dz_your_token',
    'x-business-id': 'YOUR_BUSINESS_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "overwrite_custom": false
}),
});
const data = await response.json();
```

### Python

```python
import httpx

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

payload = {
  "overwrite_custom": false
}

response = httpx.post("https://api.ondayzero.com/api/v1/businesses/{business_id}/cfo-portal/debt-schedule/instruments/{instrument_id}/payment-schedule/generate", headers=headers, json=payload)
data = response.json()
```

## See also

- HTML version: https://www.ondayzero.com/docs/reference/cfo-portal/cfo-portal-generate-debt-schedule
- OpenAPI slice: https://www.ondayzero.com/docs/reference/cfo-portal/cfo-portal-generate-debt-schedule/openapi.json
- Other endpoints in **cfo-portal**: https://www.ondayzero.com/docs/reference/cfo-portal
