# Envelope Create From Template (https://developers.doctavian.com/openapi/latest/reference/Signatures/envelope-signatures-envelope-create-from-template)

## `POST /signatures/template/{templateId}/envelope/create`

**Envelope Create From Template**

Creates an envelope from a stored template, filling its placeholder roles with real people. The envelope inherits the envelope template's documents, fields, signing order and notification settings; the request supplies only what differs for this instance.

Recipients and sign groups are matched to the template by `templateRole`, not by position or id. A `templateRole` that the template does not define has nothing to override; a recipient `templateRole` the template defines but the request omits keeps the template's stored values.

When the envelope template has sign groups, `signGroups` is mandatory and must include an entry for every one of them, naming each by its `templateRole`, even when nothing about the group is overridden — for example `{"templateRole": "Approvers"}`. A request that leaves any of the template's sign groups out, including one that sends an empty `signGroups` array, fails with `500` `FUNCTION_EXECUTION_ERROR`. When the template has no sign groups, `signGroups` can be left out.

There are no documents in this request. They come from the template, already in Storage from when the template was created, so `signatures-document-upload` is not part of this flow — upload documents when building the template with `signatures-template-create` instead.

Only `template.subject` and `template.message` can be overridden at envelope level. Sender identity, signing order, expiry, reminders, locale and time zone come from the template, and changing them means updating the template with `signatures-template-update`.

The result is an ordinary envelope in `Draft` status — nothing is sent to recipients by this call. Send it with `signatures-envelope-send`, and from that point it behaves exactly like an envelope created with `signatures-envelope-create`.

### Parameters
- `templateId` (path, string) **required** _(format: uuid)_ — GUID of the envelope template to create the envelope from, as returned by `signatures-template-create` in `result.data.template.id`.

### Request body (`application/json`)

- `template` (any) — Envelope-level overrides for this instance. Optional.
- `recipients` (array<RecipientTemplatePrepareInput>) — The real people filling the envelope template's placeholder roles. Each entry overrides the stored template recipient whose `templateRole` it matches.
  - `templateRole` (string) **required** — The envelope template's placeholder role this entry fills, for example `Counterparty`. Mandatory; rejected with `RECIPIENT_TEMPLATE_ROLE_REQUIRED` when absent. This is the only link between the request and the template — matching is by this value, not by position.
  - `name` (string) — Real name of the person filling this role, replacing any default stored on the envelope template.
  - `email` (string) _(format: email)_ — Real email address of the person filling this role, replacing any default stored on the envelope template. This is where their notification is sent. Rejected with `RECIPIENT_INVALID_EMAIL_ADDRESS` when it is not a valid address.
  - `hostEmail` (string) _(format: email)_ — Email address of the person who facilitates in-person signing for this recipient. That host runs the signing session, and must open the signing using this exact address — an address that does not match cannot open it. The notification for this recipient goes to the host, not to the recipient, and tells the host the signing is an in-person flow. Only the address format is checked here, with `HOST_INVALID_EMAIL_ADDRESS` on a malformed value. It applies when the envelope template gives this role the `inpersonsigner` role.
  - `isMfaEnabled` (boolean) — Whether this recipient must pass multi-factor authentication before signing. Requires the subscription to include MFA. When the account's MFA channel is not email, `phoneNumber` becomes mandatory.
  - `phoneNumber` (string) — Phone number used to deliver this recipient's multi-factor authentication code. Mandatory when `isMfaEnabled` is true and the account's MFA channel is not email. No format is enforced.
  - `language` (any) — Language this recipient's signing pages are shown in, replacing the language stored on the envelope template's placeholder. Optional. Must be `en` or `es`, matched without regard to case and stored in lowercase; any other value is rejected with `RECIPIENT_LANGUAGE_INVALID`. When omitted, the recipient keeps the placeholder's language from the envelope template.
  - `externalContext` (any) — Arbitrary JSON object for this recipient, stored with it and echoed back unchanged in the response. Its shape is not validated, fixed or interpreted — use it for whatever the integration needs, such as your own record id or a correlation key. One common use is matching the entry in the response back to the recipient you sent: the response returns server-generated ids and does not echo the client reference id, so an `externalContext` is what ties the two together.
- `signGroups` (array<SignGroupTemplatePrepareInput>) — Overrides for the envelope template's placeholder sign groups, matched by `templateRole`. Mandatory when the envelope template has sign groups: include an entry for every one of them, naming each by its `templateRole`, even when nothing about it is overridden, such as `{"templateRole": "Approvers"}`. Leaving any of them out, or sending an empty array, fails with `500` `FUNCTION_EXECUTION_ERROR`. Can be left out when the template has no sign groups.
  - `templateRole` (string) **required** — The envelope template's placeholder sign group this entry fills. Mandatory; rejected with `SIGN_GROUP_TEMPLATE_ROLE_REQUIRED` when absent. Matching is by this value, not by position.
  - `name` (string) — Display name for the group on this envelope, replacing any default stored on the envelope template.
  - `language` (any) — Language the signing pages are shown in for every member of this sign group on the new envelope, replacing the language each member's placeholder stores on the envelope template. Optional. Must be `en` or `es`, matched without regard to case and stored in lowercase; any other value is rejected with `RECIPIENT_LANGUAGE_INVALID`. When omitted, null or empty, each member keeps their own language from the envelope template.
- `externalContext` (any) — Arbitrary JSON object supplied by the caller and echoed back unchanged in the response envelope, on success and on error alike. Its shape is not validated, fixed or interpreted. To store a context with the new envelope, send it as `template.externalContext`.

### Responses

#### `201` — The envelope was created from the envelope template, in `Draft` status. No notification is sent to recipients by this call. `result.data` is the new envelope in full, in the same shape `signatures-envelope-get` returns, including the documents and fields copied from the template and the `template.externalContext` sent on this request, stored as `envelope.externalContext`. `result.data.envelope.id` is an **envelope** id, not a template id — the template is unchanged and can be reused.

`application/json`:

_any_

#### `400` — The request was rejected. `error.innerErrors[].code` identifies the specific problem. Template roles: `RECIPIENT_TEMPLATE_ROLE_REQUIRED` when a recipient entry carries no `templateRole`, `SIGN_GROUP_TEMPLATE_ROLE_REQUIRED` when a sign group entry carries none. Recipients: `RECIPIENT_INVALID_EMAIL_ADDRESS`, `HOST_INVALID_EMAIL_ADDRESS`. Language: `RECIPIENT_LANGUAGE_INVALID` when a `recipients[].language` or `signGroups[].language` is sent with an unsupported value, such as `fr` or `en-US`. The supported values are `en` and `es`, in any letter case. `language` is optional, and leaving it out is not an error. A `templateId` that does not identify an envelope template the caller can use is also rejected here.

`application/json`:

- `error` (object) **required** — What went wrong. `statusCode` and `message` describe the failure category, `innerErrors` the specific causes.
  - `innerErrors` (array<object>) **required** — One entry per distinct problem found with the request. At least one entry is always present, and a request failing several checks reports each of them separately -- read the whole array rather than only the first entry.
    - `code` (string) **required** — Stable, machine-readable Doctavian error code identifying what went wrong, in SCREAMING_SNAKE_CASE. This is the field to branch on in code: the two message fields are prose and may be reworded, but a code, once published, keeps its meaning.
    - `message` (string) **required** — Technical explanation of this specific failure, written for developers and logs. May reference internal specifics and is not safe to show an end user -- use `userMessage` for anything user-facing.
    - `userMessage` (string) **required** — The same failure phrased for an end user and safe to display in a UI verbatim. Says what the user can do about the problem where there is something to do, and never exposes internal detail.
    - `urn` (string) — The request property this error concerns, when the error is about one property. Optional: most errors leave it out. Named by the property's server-side name in PascalCase, not the JSON field name — `TemplateName` for `template.templateName`. Not related to the `urn` that identifies a file elsewhere in the API.
    - `eventId` (string) _(format: uuid)_ — Identifier of the logged failure behind this entry. Present only when the failure was logged, so treat it as optional. Quote it together with `operationId` when reporting the problem to support.
  - `message` (string) **required** — Short summary of the failure category, mirroring the HTTP status text (e.g. `Bad Request`). It names the class of failure only; the specific cause is in `innerErrors`.
  - `statusCode` (integer) **required** — HTTP status code of the error, repeated inside the body so the envelope stays self-contained when it is logged or forwarded. Always a number, never a string, and always equal to the response's own HTTP status.
  - `externalErrors` (array<any>) — Additional error detail attached as the server produced it. Each entry can be any JSON value and its shape is not fixed: an object returned by an external service the request depended on — such as the Google Apps Script execution layer used for `gdoc`, `gsheet` and `gslide` generation — or a plain string, such as the message of an unhandled exception. Use it for diagnostics only, and branch on `innerErrors[].code` instead. Empty or absent when there is nothing to add.
- `dateTime` (string) **required** _(format: date-time)_ — UTC timestamp when the error response was generated, with between three and seven decimal places. Doctavian's own responses end in `Z`; a response from the gateway — a `401` for a missing or invalid credential, or a `404` for a request that matches no operation — has seven decimal places and ends in `+00:00` instead.
- `operationId` (string) — Identifier of this operation in Doctavian's Azure logs, generated per request and returned on both success and failure. This is the primary reference to quote when reporting a problem to support; when `eventId` is also present, quote both. Left out of a response from the gateway, which answers some requests before they reach Doctavian: a `401` for a missing or invalid credential, and a `404` for a request that matches no operation, such as one without a mandatory query parameter. Such a response has no operation to log, and its `origin` may be empty.
- `eventId` (string) _(format: uuid)_ — Identifier of the corresponding entry in Doctavian's server-side error log. Present only when the failure was handled and logged, so treat it as optional and don't rely on it being there. When reporting a problem to support, quote it together with `operationId`: `operationId` identifies the request that was made, `eventId` identifies the logged failure behind it, and having both is what lets support trace the request end to end. A failure can instead, or also, carry an `eventId` on individual `innerErrors` entries.
- `origin` (string) **required** — The HTTP method and full request URL that produced this response, e.g. `POST https://api.doctavian.com/v1/documents/document/generate`. Useful when the envelope is logged or forwarded away from the call that produced it.
- `userId` (string) _(format: uuid)_ — The unique identifier of the user or system that initiated the request. Left out of the response when the request carried no bearer token — a guest caller on an operation that does not require one, such as a recipient signing with a `tid` — because there is no signed-in user to identify. Also left out when the caller has no Doctavian user yet: `platform-subscription-resolve` and `platform-subscription-trial-start` run before the caller's user exists, so their responses carry no `userId`.
- `externalContext` (object) — Optional, arbitrary JSON object echoed back unchanged from the request's externalContext, if one was supplied. Used to correlate this response with the request that produced it.

#### `403` — The caller is authenticated but is not permitted to access this envelope template (`ENVELOPE_ACCESS_DENIED`). Nothing is changed.

`application/json`:

- `error` (object) **required** — What went wrong. `statusCode` and `message` describe the failure category, `innerErrors` the specific causes.
  - `innerErrors` (array<object>) **required** — One entry per distinct problem found with the request. At least one entry is always present, and a request failing several checks reports each of them separately -- read the whole array rather than only the first entry.
    - `code` (string) **required** — Stable, machine-readable Doctavian error code identifying what went wrong, in SCREAMING_SNAKE_CASE. This is the field to branch on in code: the two message fields are prose and may be reworded, but a code, once published, keeps its meaning.
    - `message` (string) **required** — Technical explanation of this specific failure, written for developers and logs. May reference internal specifics and is not safe to show an end user -- use `userMessage` for anything user-facing.
    - `userMessage` (string) **required** — The same failure phrased for an end user and safe to display in a UI verbatim. Says what the user can do about the problem where there is something to do, and never exposes internal detail.
    - `urn` (string) — The request property this error concerns, when the error is about one property. Optional: most errors leave it out. Named by the property's server-side name in PascalCase, not the JSON field name — `TemplateName` for `template.templateName`. Not related to the `urn` that identifies a file elsewhere in the API.
    - `eventId` (string) _(format: uuid)_ — Identifier of the logged failure behind this entry. Present only when the failure was logged, so treat it as optional. Quote it together with `operationId` when reporting the problem to support.
  - `message` (string) **required** — Short summary of the failure category, mirroring the HTTP status text (e.g. `Bad Request`). It names the class of failure only; the specific cause is in `innerErrors`.
  - `statusCode` (integer) **required** — HTTP status code of the error, repeated inside the body so the envelope stays self-contained when it is logged or forwarded. Always a number, never a string, and always equal to the response's own HTTP status.
  - `externalErrors` (array<any>) — Additional error detail attached as the server produced it. Each entry can be any JSON value and its shape is not fixed: an object returned by an external service the request depended on — such as the Google Apps Script execution layer used for `gdoc`, `gsheet` and `gslide` generation — or a plain string, such as the message of an unhandled exception. Use it for diagnostics only, and branch on `innerErrors[].code` instead. Empty or absent when there is nothing to add.
- `dateTime` (string) **required** _(format: date-time)_ — UTC timestamp when the error response was generated, with between three and seven decimal places. Doctavian's own responses end in `Z`; a response from the gateway — a `401` for a missing or invalid credential, or a `404` for a request that matches no operation — has seven decimal places and ends in `+00:00` instead.
- `operationId` (string) — Identifier of this operation in Doctavian's Azure logs, generated per request and returned on both success and failure. This is the primary reference to quote when reporting a problem to support; when `eventId` is also present, quote both. Left out of a response from the gateway, which answers some requests before they reach Doctavian: a `401` for a missing or invalid credential, and a `404` for a request that matches no operation, such as one without a mandatory query parameter. Such a response has no operation to log, and its `origin` may be empty.
- `eventId` (string) _(format: uuid)_ — Identifier of the corresponding entry in Doctavian's server-side error log. Present only when the failure was handled and logged, so treat it as optional and don't rely on it being there. When reporting a problem to support, quote it together with `operationId`: `operationId` identifies the request that was made, `eventId` identifies the logged failure behind it, and having both is what lets support trace the request end to end. A failure can instead, or also, carry an `eventId` on individual `innerErrors` entries.
- `origin` (string) **required** — The HTTP method and full request URL that produced this response, e.g. `POST https://api.doctavian.com/v1/documents/document/generate`. Useful when the envelope is logged or forwarded away from the call that produced it.
- `userId` (string) _(format: uuid)_ — The unique identifier of the user or system that initiated the request. Left out of the response when the request carried no bearer token — a guest caller on an operation that does not require one, such as a recipient signing with a `tid` — because there is no signed-in user to identify. Also left out when the caller has no Doctavian user yet: `platform-subscription-resolve` and `platform-subscription-trial-start` run before the caller's user exists, so their responses carry no `userId`.
- `externalContext` (object) — Optional, arbitrary JSON object echoed back unchanged from the request's externalContext, if one was supplied. Used to correlate this response with the request that produced it.

#### `404` — `templateId` is not a GUID, so the path matches no operation. This response has no body — the status code is the whole answer.

#### `500` — The envelope could not be created. Returned when a document stored with the envelope template cannot be retrieved (`FILE_NOT_EXISTS_IN_STORAGE`), and when an unhandled error occurs while building or saving the envelope (`FUNCTION_EXECUTION_ERROR`). `FUNCTION_EXECUTION_ERROR` is also what a request gets when `signGroups` does not name every one of the envelope template's sign groups by `templateRole`. Nothing is persisted and the template is unchanged. When one is available, this response carries an `eventId` identifying the logged failure — quote it together with `operationId` when reporting the problem to support.

`application/json`:

- `error` (object) **required** — What went wrong. `statusCode` and `message` describe the failure category, `innerErrors` the specific causes.
  - `innerErrors` (array<object>) **required** — One entry per distinct problem found with the request. At least one entry is always present, and a request failing several checks reports each of them separately -- read the whole array rather than only the first entry.
    - `code` (string) **required** — Stable, machine-readable Doctavian error code identifying what went wrong, in SCREAMING_SNAKE_CASE. This is the field to branch on in code: the two message fields are prose and may be reworded, but a code, once published, keeps its meaning.
    - `message` (string) **required** — Technical explanation of this specific failure, written for developers and logs. May reference internal specifics and is not safe to show an end user -- use `userMessage` for anything user-facing.
    - `userMessage` (string) **required** — The same failure phrased for an end user and safe to display in a UI verbatim. Says what the user can do about the problem where there is something to do, and never exposes internal detail.
    - `urn` (string) — The request property this error concerns, when the error is about one property. Optional: most errors leave it out. Named by the property's server-side name in PascalCase, not the JSON field name — `TemplateName` for `template.templateName`. Not related to the `urn` that identifies a file elsewhere in the API.
    - `eventId` (string) _(format: uuid)_ — Identifier of the logged failure behind this entry. Present only when the failure was logged, so treat it as optional. Quote it together with `operationId` when reporting the problem to support.
  - `message` (string) **required** — Short summary of the failure category, mirroring the HTTP status text (e.g. `Bad Request`). It names the class of failure only; the specific cause is in `innerErrors`.
  - `statusCode` (integer) **required** — HTTP status code of the error, repeated inside the body so the envelope stays self-contained when it is logged or forwarded. Always a number, never a string, and always equal to the response's own HTTP status.
  - `externalErrors` (array<any>) — Additional error detail attached as the server produced it. Each entry can be any JSON value and its shape is not fixed: an object returned by an external service the request depended on — such as the Google Apps Script execution layer used for `gdoc`, `gsheet` and `gslide` generation — or a plain string, such as the message of an unhandled exception. Use it for diagnostics only, and branch on `innerErrors[].code` instead. Empty or absent when there is nothing to add.
- `dateTime` (string) **required** _(format: date-time)_ — UTC timestamp when the error response was generated, with between three and seven decimal places. Doctavian's own responses end in `Z`; a response from the gateway — a `401` for a missing or invalid credential, or a `404` for a request that matches no operation — has seven decimal places and ends in `+00:00` instead.
- `operationId` (string) — Identifier of this operation in Doctavian's Azure logs, generated per request and returned on both success and failure. This is the primary reference to quote when reporting a problem to support; when `eventId` is also present, quote both. Left out of a response from the gateway, which answers some requests before they reach Doctavian: a `401` for a missing or invalid credential, and a `404` for a request that matches no operation, such as one without a mandatory query parameter. Such a response has no operation to log, and its `origin` may be empty.
- `eventId` (string) _(format: uuid)_ — Identifier of the corresponding entry in Doctavian's server-side error log. Present only when the failure was handled and logged, so treat it as optional and don't rely on it being there. When reporting a problem to support, quote it together with `operationId`: `operationId` identifies the request that was made, `eventId` identifies the logged failure behind it, and having both is what lets support trace the request end to end. A failure can instead, or also, carry an `eventId` on individual `innerErrors` entries.
- `origin` (string) **required** — The HTTP method and full request URL that produced this response, e.g. `POST https://api.doctavian.com/v1/documents/document/generate`. Useful when the envelope is logged or forwarded away from the call that produced it.
- `userId` (string) _(format: uuid)_ — The unique identifier of the user or system that initiated the request. Left out of the response when the request carried no bearer token — a guest caller on an operation that does not require one, such as a recipient signing with a `tid` — because there is no signed-in user to identify. Also left out when the caller has no Doctavian user yet: `platform-subscription-resolve` and `platform-subscription-trial-start` run before the caller's user exists, so their responses carry no `userId`.
- `externalContext` (object) — Optional, arbitrary JSON object echoed back unchanged from the request's externalContext, if one was supplied. Used to correlate this response with the request that produced it.