# Draft a document from a template

> POST /api/v1/templates/{id}/create-document: Draft a document from a template.

`POST https://appliflo.com/api/v1/templates/{id}/create-document`

An AppliFlo library item or official form (a lib_ id from items[]) is the app's Use: a ready item drafts with each role's person bound (an unreviewed contract needs risk_accepted: true unless the person already accepted that version); a form AppliFlo hasn't set up is imported as a new document and its fields are read, and recipients are added when you send. The e-sign rule applies at send (a fill-and-print-only form drafts, but every send refuses it). Any other id is the older contract-template model (values + recipients in party order). Saved templates: POST /saved-templates/{id}/create-document.

Send your API key in the `Authorization: Bearer` header. Every response is JSON: `{ success, data, error }`.

## Parameters

| Name | In | Required | Description |
| --- | --- | --- | --- |
| `id` | path | yes | Template id from GET /templates (items[].template_id for a lib_ item) |
| `Idempotency-Key` | header | no | A client-generated key scoping this request as a retry of a prior identical request. A replay within 24h returns the first response instead of repeating the side effect (e.g. a second send). The key is bound to the request it was first used with: the same key with a different body or target is refused (422, code idempotency_key_reused) |

## Request body (application/json)



## Responses

| Status | Description |
| --- | --- |
| 201 | Drafted document, with its fields already placed and bound to the recipients (an imported form: its fields as read). |
| 400 | invalid_json: a lib_ request body that isn't JSON (an empty body counts as {}). |
| 401 | Missing or invalid API key, or `api_key_expired` for a key past its expiry. |
| 403 | The API key's workspace does not have access to this resource, or `insufficient_scope` (with `required_scope`) for a key without the scope this route needs. |
| 404 | Resource not found in this workspace. |
| 409 | contract_risk_required: an unreviewed AppliFlo contract the person hasn't accepted (send risk_accepted: true after asking them). |
| 410 | retired: the official form was retired. |
| 422 | Request failed validation. |
| 429 | rate_limited: more than 20 official forms imported by this key in 10 minutes (as the app's import). Retry-After says when. |
| 500 | Internal error. |
| 503 | form_unavailable: the form's hosted copy is unavailable. Retry-After: 300. |

## 201 response

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `success` | true | yes |  |
| `data` | object \| object | yes |  |

See also: [Errors](https://dev.appliflo.com/guides/errors), [Rate limits](https://dev.appliflo.com/guides/rate-limits), [Idempotency](https://dev.appliflo.com/guides/idempotency).
