# POST /api/v1/contracts/{contract_id}/generate-period-invoices

> Draft the next period's invoices

- **Tag:** contracts
- **Operation ID:** `generate_period_invoices_api_v1_contracts__contract_id__generate_period_invoices_post`

## Description

Draft the next billing period's invoice from recurring (each_period) and per-unit (approved hours x price) order lines. Idempotent per (contract, period): a period already drafted is not re-drafted.

## Authentication

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

## Parameters

- `contract_id` (path, string, required)

## Request body

Schema: `GeneratePeriodInvoicesRequest`

- `period_date` (string · required) — Any date within the billing period to draft (YYYY-MM-DD).

## Responses

### 201 — Successful Response

Schema: `SuccessEnvelope_ContractInvoiceResult_`

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

### 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/contracts/{contract_id}/generate-period-invoices' \
  -H 'Authorization: Bearer dz_your_token' \
  -H 'x-business-id: YOUR_BUSINESS_ID' \
  -H 'Content-Type: application/json' \
  -d '{
  "period_date": "string"
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/contracts/{contract_id}/generate-period-invoices', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer dz_your_token',
    'x-business-id': 'YOUR_BUSINESS_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "period_date": "string"
}),
});
const data = await response.json();
```

### Python

```python
import httpx

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

payload = {
  "period_date": "string"
}

response = httpx.post("https://api.ondayzero.com/api/v1/contracts/{contract_id}/generate-period-invoices", headers=headers, json=payload)
data = response.json()
```

## See also

- HTML version: https://www.ondayzero.com/docs/reference/contracts/generate-period-invoices
- OpenAPI slice: https://www.ondayzero.com/docs/reference/contracts/generate-period-invoices/openapi.json
- Other endpoints in **contracts**: https://www.ondayzero.com/docs/reference/contracts
