# POST /api/v1/credit/cycles/close

> Close cycles and create their draws

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

## Description

Closes every cycle whose period has ended: fixes the principal, computes the disbursement fee and the full-term interest once, and sets the due date. Idempotent — a cycle already closed is skipped. Pass `dry_run` to see what would close without writing.

## Authentication

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

## Request body

Schema: `CycleCloseRequest`

- `credit_line_id` (string) — Limit to one line. Omit to sweep the business.
- `as_of` (string · date) — Treat this as today. Defaults to the current date.
- `issue_statements` (boolean) — Also mark closed cycles issued.
- `dry_run` (boolean)

## Responses

### 201 — Successful Response

Schema: `SuccessEnvelope_CycleCloseResponse_`

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

### 400 — Bad Request - Invalid input

### 401 — Unauthorized - Authentication required

### 403 — Forbidden - Insufficient permissions

### 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/credit/cycles/close' \
  -H 'Authorization: Bearer dz_your_token' \
  -H 'x-business-id: YOUR_BUSINESS_ID' \
  -H 'Content-Type: application/json' \
  -d '{
  "credit_line_id": "string",
  "as_of": "2026-01-01",
  "issue_statements": false,
  "dry_run": false
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/credit/cycles/close', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer dz_your_token',
    'x-business-id': 'YOUR_BUSINESS_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "credit_line_id": "string",
  "as_of": "2026-01-01",
  "issue_statements": false,
  "dry_run": false
}),
});
const data = await response.json();
```

### Python

```python
import httpx

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

payload = {
  "credit_line_id": "string",
  "as_of": "2026-01-01",
  "issue_statements": false,
  "dry_run": false
}

response = httpx.post("https://api.ondayzero.com/api/v1/credit/cycles/close", headers=headers, json=payload)
data = response.json()
```

## See also

- HTML version: https://www.ondayzero.com/docs/reference/credit/close-cycles
- OpenAPI slice: https://www.ondayzero.com/docs/reference/credit/close-cycles/openapi.json
- Other endpoints in **credit**: https://www.ondayzero.com/docs/reference/credit
