# POST /api/v1/subscriptions/create-templates

> Create recurring bill templates from detected patterns

- **Tag:** subscriptions
- **Operation ID:** `create_templates_from_detection`

## Description

Turn detected recurring spend into recurring bill templates in one call: name the rows (`counterparty_keys`, as listed by `GET /`) or take every row at or above `min_confidence`. Vendor, amount, cadence and first date come from the detection (re-run server-side). A row with no vendor of that name, a semi-annual row, or a vendor that already has an open template on that cadence is skipped with a reason; each row is isolated. `dry_run` plans without creating.

## Authentication

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

## Request body

Schema: `CreateTemplatesFromDetectionRequest`

- `counterparty_keys` (array · string) — counterparty_key of the detected rows to turn into templates. Omit to use min_confidence.
- `min_confidence` (number) — Every detected row at or above this confidence (keys omitted).
- `lookback_days` (integer) — Detection window; match the list you showed.
- `vendor_overrides` (object) — counterparty_key -> vendor_id for rows whose vendor is not found by name.
- `dry_run` (boolean) — Plan the templates; create nothing.
- `plan_hash` (string) — plan_hash of the dry run; refused if the patterns moved

## Responses

### 200 — Successful Response

Schema: `SuccessEnvelope_CreateTemplatesFromDetectionResponse_`

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

### 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 or expired token, an MCP OAuth token used against the REST API, 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.

### 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/subscriptions/create-templates' \
  -H 'Authorization: Bearer dz_your_token' \
  -H 'x-business-id: YOUR_BUSINESS_ID' \
  -H 'Content-Type: application/json' \
  -d '{
  "counterparty_keys": [],
  "min_confidence": 0,
  "lookback_days": 0,
  "vendor_overrides": {},
  "dry_run": false,
  "plan_hash": "string"
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/subscriptions/create-templates', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer dz_your_token',
    'x-business-id': 'YOUR_BUSINESS_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "counterparty_keys": [],
  "min_confidence": 0,
  "lookback_days": 0,
  "vendor_overrides": {},
  "dry_run": false,
  "plan_hash": "string"
}),
});
const data = await response.json();
```

### Python

```python
import httpx

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

payload = {'counterparty_keys': [],
 'min_confidence': 0,
 'lookback_days': 0,
 'vendor_overrides': {},
 'dry_run': False,
 'plan_hash': 'string'}

response = httpx.post("https://api.ondayzero.com/api/v1/subscriptions/create-templates", headers=headers, json=payload)
data = response.json()
```

## See also

- HTML version: https://www.ondayzero.com/docs/reference/subscriptions/create-templates-from-detection
- OpenAPI slice: https://www.ondayzero.com/docs/reference/subscriptions/create-templates-from-detection/openapi.json
- Other endpoints in **subscriptions**: https://www.ondayzero.com/docs/reference/subscriptions (markdown bundle: https://www.ondayzero.com/docs/reference/subscriptions.md, OpenAPI: https://www.ondayzero.com/docs/reference/subscriptions/openapi.json)
- Endpoint catalog: https://www.ondayzero.com/docs/reference/index.md
