# Save a draft document as a template

> POST /api/v1/saved-templates: Save a draft document as a template.

`POST https://appliflo.com/api/v1/saved-templates`

Copies the document's PDF and its fields into a new saved template, and carries over any saved mappings the document's form has. The document itself is not changed.

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

## Request body (application/json)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `document_id` | string | yes | A draft document with its fields detected or placed |
| `name` | string | no | Defaults to the document's name. Up to 120 characters |
| `roles` | string[] | no | Recipient role labels in signing order, e.g. ["Client", "Agent"]. Up to 4 items |

## Responses

| Status | Description |
| --- | --- |
| 201 | The new saved template. |
| 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. |
| 422 | Request failed validation. |
| 500 | Internal error. |

## 201 response

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `success` | true | yes |  |
| `data` | object | yes |  |
| `data.saved_template` | object | yes |  |
| `data.saved_template.template_id` | string | yes |  |
| `data.saved_template.kind` | "saved" | yes |  |
| `data.saved_template.name` | string | yes |  |
| `data.saved_template.status` | string | yes | Only a ready template can be sent; a draft is refused with 409 template_not_ready. One of: draft, ready |
| `data.saved_template.version` | integer \| null | yes | The current version (null while draft). POST /templates/{id}/bulk requires it |
| `data.saved_template.field_count` | integer | yes | At least 0 |
| `data.saved_template.pages` | integer | yes | At least 1 |
| `data.saved_template.roles` | object[] | yes | Recipient roles, in signing order (the current version's; a draft's planned ones) |
| `data.saved_template.roles[].key` | string | yes | The key send and bulk take in `people` / `recipients[].role`, e.g. "r1" |
| `data.saved_template.roles[].label` | string | yes | The role's name, e.g. "Client" |
| `data.saved_template.roles[].kind` | string | yes | signer: fills and signs; filler: fills only. One of: signer, filler |
| `data.saved_template.roles[].order` | integer | yes | Signing order. At least 1 |
| `data.saved_template.sender_fields` | object[] | yes | The boxes the sender fills (empty while draft) |
| `data.saved_template.sender_fields[].index` | integer | yes | The prefill key. At least 0 |
| `data.saved_template.sender_fields[].label` | string \| null | yes |  |
| `data.saved_template.sender_fields[].type` | string | yes | One of: text, checkbox, signature |
| `data.saved_template.sender_fields[].semantic_type` | string | yes |  |
| `data.saved_template.sender_fields[].group_key` | string \| null | yes | The choice question this box is an option of (answer with an option value) |
| `data.saved_template.sender_fields[].option_value` | string \| null | yes |  |
| `data.saved_template.sender_fields[].bulk` | boolean | yes | A plain text box a bulk row's prefill may set |
| `data.saved_template.fixed_fields` | object[] | yes | The boxes the template fills itself (empty while draft) |
| `data.saved_template.fixed_fields[].index` | integer | yes | The fixed_overrides key. At least 0 |
| `data.saved_template.fixed_fields[].label` | string \| null | yes |  |
| `data.saved_template.fixed_fields[].type` | string | yes | One of: text, checkbox, signature |
| `data.saved_template.fixed_fields[].locked` | boolean | yes | True: set by the template, an override is 422 locked_field |
| `data.saved_template.fixed_fields[].bulk` | boolean | yes | A Default text box a bulk row's prefill may set (its value becomes that row's override) |
| `data.saved_template.source` | string | yes | doc: saved from a Docs doc (no PDF; send it to many, or use it from Docs). One of: document, official, upload, doc |
| `data.saved_template.official_form_slug` | string \| null | yes |  |
| `data.saved_template.created_at` | string | yes | Format: date-time |
| `data.saved_template.updated_at` | string | yes | Format: date-time |
| `data.mappings_copied` | integer | yes | At least 0 |

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).
