# POST /api/v1/businesses/generate-coa

> Generate a COA template using AI

- **Tag:** businesses
- **Operation ID:** `generate_coa_template_api_v1_businesses_generate_coa_post`

## Description

Uses AI to generate a complete chart of accounts template based on a business description.

## Authentication

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

## Request body

Schema: `CoaGenerateRequest`

- `business_description` (string · required) — Description of the business including industry, size, and accounting needs. E.g. 'Small e-commerce business selling handmade jewelry, accrual basis, US-based'
- `accounting_basis` (string) — Preferred accounting basis. If omitted, the AI will choose based on business description.
- `currency` (string) — Primary currency (USD, CAD, AUD, EUR, or GBP).
- `include_inventory` (boolean) — Whether to include inventory-related accounts (COGS, inventory assets, etc.).

## Responses

### 201 — Successful Response

Schema: `CoaGenerateResponse`

- `template` (CustomCoaTemplate · required) → `CustomCoaTemplate` — Generated COA template ready for use in business creation
  - `ledgers` (array · CustomCoaLedger · required) → `CustomCoaLedger` — List of ledger definitions for the custom COA
- `accounting_basis` (string · required) — The accounting basis used for this template (cash or accrual)
- `summary` (string · required) — Brief AI explanation of the generated template and why accounts were chosen
- `ledger_count` (integer) — Number of ledgers in the generated template

### 400 — Bad Request - Invalid input

### 401 — Unauthorized - Authentication required

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

### JavaScript

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

### Python

```python
import httpx

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

payload = {
  "business_description": "string"
}

response = httpx.post("https://api.ondayzero.com/api/v1/businesses/generate-coa", headers=headers, json=payload)
data = response.json()
```

## See also

- HTML version: https://www.ondayzero.com/docs/reference/businesses/generate-coa-template
- OpenAPI slice: https://www.ondayzero.com/docs/reference/businesses/generate-coa-template/openapi.json
- Other endpoints in **businesses**: https://www.ondayzero.com/docs/reference/businesses
