# Document Generate (https://developers.doctavian.com/openapi/latest/reference/Documents/operations-documents-document-generate)

## `POST /documents/document/generate`

**Document Generate**

Generates a file from a template and delivers it, synchronously. Supply three things: the `template` to generate from, the `data` that populates it, and the `document` configuration describing the output and where it goes.

The call blocks until generation finishes and returns the outcome directly — HTTP `200` with the generated file's identity and usage metrics, or an error with the reason it failed. The success body reports `201` in `result.statusCode`. Nothing is written to the delivery target when the request fails.

Templates may be Microsoft formats (`docx`, `xlsx`, `xlsm`, `pptx`) held in Storage or OneDrive, or Google Workspace formats (`gdoc`, `gsheet`, `gslide`) held in Google Drive, and the output can be delivered to Storage, OneDrive, or Google Drive with optional sharing links. `pdf` can be produced from any template. The template's own content drives what the data is used for — merge fields, expressions, repeaters, tables — and it can pull in further templates through an Include directive, listed in `template.relatedItems`. Data comes either from a stored file used as-is, or from an external API queried at generation time via the `GraphQL` load method.

Which format can be loaded from where, which output formats a given template can produce, and where each output format can be delivered are all validated together; the request body description sets out those rules in one place.

Use `documents-document-generate-async` instead when generation may take long enough that you don't want to hold the connection open, or when your integration is callback-driven. That variant acknowledges immediately with an empty `200` and delivers this same result to a callback URL.

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

- `externalContext` (object) — Optional, arbitrary JSON object supplied by the caller to correlate this request with an external system, process, or transaction (e.g. an order ID or a trace ID from your own system). Its shape isn't validated or interpreted by Doctavian — any JSON object is accepted — and the same object is returned unchanged as `externalContext` in the response envelope, so you can match a response back to the request that produced it. Omit it if you don't need this correlation.
- `template` (object) **required** — The template used to generate the final document. Locating the template file requires either `url` alone, or `urn` together with `loadMethod` — supplying neither pair means the template can't be resolved and the request fails with a 400 response.
  - `name` (string) — Optional label for this template. Only meaningful when this template object is placed inside `relatedItems`: it must then match the reference name used by an Include directive inside the primary template's content, so the merge engine knows which related file to pull in. Has no effect on the top-level template being generated.
  - `urn` (string) — Identifier of the template in the storage selected by `loadMethod` — a Storage key, a OneDrive file ID, or a Google Drive file ID, depending on which `loadMethod` is set. Mandatory together with `loadMethod` when `url` is not supplied; if both `urn`+`loadMethod` and `url` are omitted, the template can't be located and the request fails with a 400 `TEMPLATE_NOT_FOUND` response. If the urn doesn't resolve to an existing file for the given `loadMethod`, the request also fails with a 400 `TEMPLATE_NOT_FOUND` response.
  - `fileFormat` (any) **required** — Mandatory. The template's file format, without a leading dot. Must be consistent with `loadMethod`: `gdoc`, `gsheet`, and `gslide` are Google Workspace formats and are only usable when `loadMethod` is `GoogleDrive`; `docx`, `xlsx`, `xlsm`, and `pptx` are Microsoft formats and are only usable when `loadMethod` is `Storage` or `OneDrive`.
  - `loadMethod` (any) — Where the template file identified by `urn` is stored: Doctavian's internal Storage, or a connected OneDrive or Google Drive. Mandatory together with `urn` when `url` is not supplied. When `OneDrive` or `GoogleDrive` is used, the file must be accessible to the drive account associated with the request's Auth token, or the request fails.
  - `options` (object) — Load options for the template file, passed through to the rendering engine that opens it. Only the property matching the template's `fileFormat` is read (`docxLoadOptions` for `docx`, `xlsxLoadOptions` for `xlsx`, `pptxLoadOptions` for `pptx`). An `xlsm` template has no load options, and neither do the Google formats (`gdoc`, `gsheet`, `gslide`), which are rendered by Google instead. Entirely optional.
    - `docxLoadOptions` (string) _(default: "{ \"PreserveUnsupportedFeatures\": true }")_ — JSON-serialized Word load options, as a string (not a nested JSON object). Only used when the template's `fileFormat` is `docx`. If omitted, defaults to `{"PreserveUnsupportedFeatures": true}`, so content the renderer does not natively support is preserved rather than stripped when the template is loaded. See more: [DocxLoadOptions](https://www.gemboxsoftware.com/document/docs/GemBox.Document.DocxLoadOptions.html).
    - `xlsxLoadOptions` (string) — JSON-serialized Excel load options, as a string (not a nested JSON object). Only used when the template's `fileFormat` is `xlsx`. Optional; if omitted, the renderer's own defaults apply. See more: [XlsxLoadOptions](https://www.gemboxsoftware.com/spreadsheet/docs/GemBox.Spreadsheet.XlsxLoadOptions.html).
    - `pptxLoadOptions` (string) — JSON-serialized PowerPoint load options, as a string (not a nested JSON object). Only used when the template's `fileFormat` is `pptx`. Optional; if omitted, the renderer's own defaults apply. See more: [PptxLoadOptions](https://www.gemboxsoftware.com/presentation/docs/GemBox.Presentation.PptxLoadOptions.html).
  - `relatedItems` (array<object>) — Additional templates that the primary template's content can pull in via an Include directive (e.g. a standard addendum reused across several main templates). Optional; omit it if the template doesn't include any other files. Each entry is a template reference with the same shape and load rules as the top-level `template` object.
    - `name` (string) **required** — Reference name for this related template. Mandatory: this is the name an Include directive inside the primary template's content uses to pull in this file, so it must match that reference exactly or the include resolves to nothing.
    - `urn` (string) — Identifier of the related template in the storage selected by `loadMethod` — a Storage key, a OneDrive file ID, or a Google Drive file ID. Mandatory together with `loadMethod` when `url` is not supplied for this entry.
    - `fileFormat` (any) **required** — Mandatory. File format of this related template, without a leading dot. Follows the same loadMethod pairing rule as the top-level template's `fileFormat`: Google formats require `loadMethod: GoogleDrive`; Microsoft formats require `loadMethod: Storage` or `OneDrive`.
    - `loadMethod` (any) — Where this related template's file is stored. Mandatory together with `urn` when `url` is not supplied for this entry.
    - `url` (string) — Direct download URL for this related template, used instead of `urn`+`loadMethod` to locate the file. Optional; supply either this or `urn`+`loadMethod`, not both.
    - `options` (object) — Load options for this related template, following the same per-format rules as `template.options`. Optional.
      - `docxLoadOptions` (string) _(default: "{ \"PreserveUnsupportedFeatures\": true }")_ — JSON-serialized Word load options, as a string (not a nested JSON object). Only used when this entry's `fileFormat` is `docx`. If omitted, defaults to `{"PreserveUnsupportedFeatures": true}`, so content the renderer does not natively support is preserved rather than stripped. See more: [DocxLoadOptions](https://www.gemboxsoftware.com/document/docs/GemBox.Document.DocxLoadOptions.html).
      - `xlsxLoadOptions` (string) — JSON-serialized Excel load options, as a string (not a nested JSON object). Only used when this entry's `fileFormat` is `xlsx`. Optional; if omitted, the renderer's own defaults apply. See more: [XlsxLoadOptions](https://www.gemboxsoftware.com/spreadsheet/docs/GemBox.Spreadsheet.XlsxLoadOptions.html).
      - `pptxLoadOptions` (string) — JSON-serialized PowerPoint load options, as a string (not a nested JSON object). Only used when this entry's `fileFormat` is `pptx`. Optional; if omitted, the renderer's own defaults apply. See more: [PptxLoadOptions](https://www.gemboxsoftware.com/presentation/docs/GemBox.Presentation.PptxLoadOptions.html).
  - `url` (string) — Direct download URL for the template file. When set, the file is downloaded from this URL directly into memory rather than being looked up via `urn`+`loadMethod`. Supply either this field alone, or `urn`+`loadMethod` together — not both. Omitting all three (`url`, `urn`, `loadMethod`) causes the request to fail with a 400 `TEMPLATE_NOT_FOUND` response.
- `data` (object) **required** — The data source that supplies values consumed by the template's merge fields, expressions, and other data-driven elements (e.g. repeaters, tables). Unlike `template`, `data` has no `url` alternative — `urn` and `loadMethod` are both always mandatory.
  - `loadMethod` (any) **required** — Mandatory. How the data in `urn` is retrieved. `Storage`, `OneDrive`, and `GoogleDrive` treat `urn` as a static file location and use its contents as-is (for a drive, the file must be accessible to the account tied to the request's Auth token). `GraphQL` treats `urn` as the URL of an external API to call, combining it with `query` and `variables` to build the request and transform the result into the data consumed by the template.
  - `urn` (string) **required** — Mandatory. Meaning depends on `loadMethod`: a Storage key, a OneDrive file ID, or a Google Drive file ID when `loadMethod` is `Storage`, `OneDrive`, or `GoogleDrive`; the URL of the external API to call when `loadMethod` is `GraphQL`. In the `GraphQL` case, the target doesn't have to be a true GraphQL endpoint — it can also be a plain REST endpoint, which is called with a `PUT` request instead of a GraphQL query.
  - `variables` (array<DataVariable>) — Optional list of named values injected into the data before merging. How each entry is applied depends on its `type`: a `global` variable is added as a top-level property on the data object; a `fieldExpression` variable is placed at the specific location given by its `name` (see `name`'s description); a `graphql` variable supplies a value for a variable referenced in `query`. Omit this array entirely if the template needs no additional or computed values beyond what `urn` already provides.
    - `name` (string) **required** — Mandatory. The variable's name. For `type: fieldExpression`, use a `Path.Name` format (e.g. `Account.CreatedDate`) so the engine knows which object in the data the computed value belongs to; for `type: global` or `type: graphql`, this is just the variable's own name.
    - `value` (string) **required** — Mandatory. The variable's value. For `type: graphql`, this is always a fixed literal value. For `type: global` or `type: fieldExpression`, this can be a fixed literal, a function expression (e.g. `{!$now()}`), or a reference to one or more other variables, and these can be combined in a single expression.
    - `type` (string) **required** _(enum: "fieldExpression", "graphql", "global")_ — Mandatory. Controls how this variable is applied — see the `variables` array description for what each value does. Must match one of `fieldExpression`, `graphql`, or `global` exactly, including case.
  - `query` (string) — GraphQL request body, as a JSON-serialized string (e.g. `"{\"query\":\"{...}\"}"`). Only read when `loadMethod` is `GraphQL`; ignored for every other `loadMethod`. Optional even when `loadMethod` is `GraphQL`.
  - `embedded` (string) — Optional custom metadata to write into the generated file's document properties (e.g. PDF metadata), as a JSON-serialized string of key-value pairs. This metadata isn't visible in the document's rendered content but can be read back from the file's properties. Omit it if no custom metadata is needed.
- `document` (object) **required** — Configuration for the document produced by this request: how dates and numbers are formatted, the output file's name and format, and where it's delivered.
  - `timeZone` (string) **required** — Mandatory. Timezone used to render date/time values in the generated document. Must be one of the supported timezone identifiers listed in the [locale reference](https://developers.doctavian.com/en/function-reference/locales); an unsupported value causes the request to fail with a 400 response.
  - `locale` (string) **required** — Mandatory. Locale used for language- and region-specific formatting (dates, numbers, currency) in the generated document. Must be one of the supported locale codes listed in the [locale reference](https://developers.doctavian.com/en/function-reference/locales), which follows the [Unicode CLDR Project](https://cldr.unicode.org/) naming (e.g. `en_GB`, `es_MX`). An unsupported value fails with `500` `LOCALE_DOWNLOAD_FAILED`, followed by `GENERATE_FUNCTION_FAILED`.
  - `name` (string) **required** — Mandatory. Name of the generated file, without a file extension — the extension is derived from `fileFormat` automatically.
  - `fileFormat` (string) **required** _(enum: "docx", "xlsx", "xlsm", "pptx", "gdoc", "gsheet", "gslide", "pdf", "csv")_ — Mandatory. Output format of the generated file, which must be one the template's `fileFormat` can produce: a `docx` template produces `docx` or `pdf`; `xlsx` produces `xlsx`, `pdf` or `csv`; `xlsm` produces `xlsm`, `xlsx`, `pdf` or `csv`; `pptx` produces `pptx` or `pdf`; `gdoc` produces `gdoc`, `docx` or `pdf`; `gsheet` produces `gsheet`, `xlsx`, `pdf` or `csv`; and `gslide` produces `gslide`, `pptx` or `pdf`. Requesting a format the template can't produce causes the request to fail with a 400 response.
  - `deliveryMethod` (string) **required** _(enum: "Storage", "OneDrive", "GoogleDrive")_ — Mandatory. Where the generated file is delivered. Constrained by `fileFormat`: `gdoc`, `gsheet`, and `gslide` can only be delivered to `GoogleDrive`; `docx`, `xlsx`, `xlsm`, and `pptx` can be delivered to `Storage` or `OneDrive`; `pdf` and `csv` can be delivered to any of the three. Requesting a delivery method the file format doesn't support causes the request to fail with a 400 response.
  - `path` (string) **required** — Mandatory. Destination folder for the generated file. `"root"` (for `Storage`) and `""` (for `OneDrive` or `GoogleDrive`) are the root of the selected location, not a placeholder to fill in — to target a subfolder, concatenate the relative subfolder path onto that root value rather than replacing it. Getting this wrong for the selected `deliveryMethod` — including the root value itself — causes the request to fail, because the generated file can't be saved to a location that doesn't resolve.
  - `options` (object) — Save options for the output file, passed through to the rendering engine that writes it, plus delivery-specific sharing and generation settings. Only the save-options property matching `fileFormat` is read; there is no equivalent option set for `xlsm`, `gdoc`, `gsheet` or `gslide`. All properties here are optional.
    - `pdfSaveOptions` (string) _(default: "{ \"ConformanceLevel\": \"PdfA3a\", \"Version\": \"PDF_1_7\", \"ImageDpi\": 750, \"SelectionType\": \"EntireFile\" }")_ — JSON-serialized PDF save options, as a string. Only used when `fileFormat` is `pdf`. If omitted, defaults to `{"ConformanceLevel": "PdfA3a", "Version": "PDF_1_7", "ImageDpi": 750, "SelectionType": "EntireFile"}`, which gives the widest PDF/A conformance, a balance of image size versus quality, and — for an `xlsx` source — ensures every sheet is included rather than just the active one. `ConformanceLevel` selects the PDF/A archival standard applied to the output. Accepted values: `PdfA1a` (full accessibility, tagged structure), `PdfA1b` (visual reproducibility only), `PdfA2a`, `PdfA2b`, `PdfA2u` (PDF 1.7 based; `u` requires Unicode text mapping), `PdfA3a`, `PdfA3b`, `PdfA3u` (as PDF/A-2 but allowing embedded file attachments). `Version` selects the underlying PDF specification. Accepted values: `PDF_1_4` (broadest compatibility), `PDF_1_5`, `PDF_1_6`, `PDF_1_7`, `PDF_2_0`. See more: [PdfSaveOptions](https://www.gemboxsoftware.com/pdf/docs/GemBox.Pdf.PdfSaveOptions.html).
    - `docxSaveOptions` (string) — JSON-serialized Word save options, as a string. Only used when `fileFormat` is `docx`. Optional; if omitted, the renderer's own defaults apply. See more: [DocxSaveOptions](https://www.gemboxsoftware.com/document/docs/GemBox.Document.DocxSaveOptions.html).
    - `onedrive` (object) — Sharing rights applied to the generated file when `deliveryMethod` is `OneDrive`. Ignored for any other `deliveryMethod`. All properties are optional and default to no sharing beyond the owner's own access.
      - `viewAnonymous` (boolean) _(default: false)_ — Creates a link that lets anyone with it view the generated document, without signing in. Defaults to `false` (no anonymous view link created).
      - `editAnonymous` (boolean) _(default: false)_ — Creates a link that lets anyone with it edit the generated document, without signing in. Defaults to `false` (no anonymous edit link created).
      - `viewOrganization` (boolean) _(default: false)_ — Creates a link that lets anyone signed into the same organization view the generated document. Defaults to `false` (no organization-wide view link created).
      - `editOrganization` (boolean) _(default: false)_ — Creates a link that lets anyone signed into the same organization edit the generated document. Defaults to `false` (no organization-wide edit link created).
      - `editUsers` (array<string>) — Email addresses of specific users to grant edit access to. Optional; omit or leave empty for no per-user edit sharing.
      - `viewUsers` (array<string>) — Email addresses of specific users to grant view access to. Optional; omit or leave empty for no per-user view sharing.
    - `xlsxSaveOptions` (string) — JSON-serialized Excel save options, as a string. Only used when `fileFormat` is `xlsx` or `csv`. Optional; if omitted, the renderer's own defaults apply. See more: [XlsxSaveOptions](https://www.gemboxsoftware.com/spreadsheet/docs/GemBox.Spreadsheet.XlsxSaveOptions.html).
    - `pptxSaveOptions` (string) — JSON-serialized PowerPoint save options, as a string. Only used when `fileFormat` is `pptx`. Optional; if omitted, the renderer's own defaults apply. See more: [PptxSaveOptions](https://www.gemboxsoftware.com/presentation/docs/GemBox.Presentation.PptxSaveOptions.html).
    - `googleGenerate` (object) — Generation performance options used only when the template's `fileFormat` is a Google format (`gdoc`, `gsheet`, `gslide`). Ignored for Microsoft-format templates.
      - `nativeMergeEnabled` (boolean) _(default: false)_ — Merges all merge fields in a single batched call to the Google API instead of one call per field. Speeds up generation for templates with many simple merge fields, but can be slower than the default for templates that use repeaters or tables, since those already make one call per repeated item regardless of this setting; also gives little benefit for templates with only a few merge fields. Defaults to `false`.
      - `nativeImageMergeEnabled` (boolean) _(default: false)_ — Merges all images in a single batched call to the Google API instead of one call per image. Speeds up generation for templates with many images, but can be slower than the default for templates with only a few. Defaults to `false`.
      - `functionsExternalUrlAllowed` (boolean) _(default: false)_ — Allows Google Sheets formulas in the template to fetch images from external URLs during generation. Defaults to `false`.
    - `googleDrive` (object) — Sharing rights applied to the generated file when `deliveryMethod` is `GoogleDrive`. Ignored for any other `deliveryMethod`. All properties are optional and default to no sharing beyond the owner's own access.
      - `viewAnonymous` (boolean) _(default: false)_ — Creates a link that lets anyone with it view the generated document, without signing in. Defaults to `false` (no anonymous view link created).
      - `editAnonymous` (boolean) _(default: false)_ — Creates a link that lets anyone with it edit the generated document, without signing in. Defaults to `false` (no anonymous edit link created).
      - `viewOrganization` (boolean) _(default: false)_ — Creates a link that lets anyone signed into the same organization view the generated document. Defaults to `false` (no organization-wide view link created).
      - `editOrganization` (boolean) _(default: false)_ — Creates a link that lets anyone signed into the same organization edit the generated document. Defaults to `false` (no organization-wide edit link created).
      - `editUsers` (array<string>) — Email addresses of specific users to grant edit access to. Optional; omit or leave empty for no per-user edit sharing.
      - `viewUsers` (array<string>) — Email addresses of specific users to grant view access to. Optional; omit or leave empty for no per-user view sharing.

### Responses

#### `200` — The document was generated and delivered to the target named by `deliveryMethod`. The response is sent with HTTP `200`, while `result.statusCode` in the body reports `201` and `result.message` `Created`. `result.data.document` identifies the generated file: `deliveryMethod`, `name`, `fileFormat`, and `urn` are always present. `urn` is a GUID for `Storage` deliveries and the drive's own file identifier for `OneDrive` and `GoogleDrive`. Two fields appear only for drive deliveries: `uri`, the document's URL, and `oneDriveProperties` or `googleDriveProperties`, holding the sharing links created for whatever was requested under `document.options`. A `Storage` delivery produces neither, so reference the file by `urn` in that case. Sharing is best-effort: if access could not be granted to some of the users listed in `viewUsers` or `editUsers`, they come back in `viewUsersFailed` or `editUsersFailed` and the document is still generated and delivered. Those two fields are absent entirely when every user succeeded. `consumption` reports what the operation counted against the subscription: one entry, `documents-generated`, `spreadsheets-generated` or `presentations-generated` depending on the kind of file produced. `externalContext` is whatever the request sent, echoed back unchanged. `operationId` identifies this operation in Doctavian's logs and is the reference to quote in a support request.

`application/json`:

_any_

#### `400` — The request was rejected and no document was generated, so nothing was written to the delivery target and no consumption is counted. Each entry in `error.innerErrors` carries a machine-readable `code`, a technical `message` for logs, a `userMessage` safe to display to an end user, and an `eventId` when the failure was logged. One request can return several entries: an invalid `loadMethod` returns `INVALID_LOAD_METHOD_SPECIFIED` followed by `GENERATE_FUNCTION_FAILED`. `TEMPLATE_NOT_FOUND` means the template couldn't be resolved — either `urn`+`loadMethod` didn't locate a file, `url` couldn't be downloaded, or none of the three was supplied. The other common cause is a combination the format rules don't allow, such as an output `fileFormat` the template can't produce or a `deliveryMethod` that format can't be delivered to; those rules are set out in the request body description. `error.externalErrors` carries raw detail from an external service when the failure originated there rather than in the request itself — for example the Google Apps Script layer used to generate `gdoc`, `gsheet`, and `gslide` output. It is absent or empty otherwise. `externalContext` is echoed back unchanged, so a failed request can still be correlated with the call that produced it. One `400` has a different body. When the authorization headers that the gateway adds to the request cannot be read, the request is rejected before any work starts with a bare object, `{ "message": "<reason>" }`, instead of the error envelope. A request that passes the gateway's own token check does not normally reach this case.

`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` — A usage limit has been reached, so nothing was done (`LIMIT_BREACH`). The limit is checked before any work starts, against the dimension this request would be counted under. `message` and `userMessage` both name what the limit applies to, the current usage, the limit and the period, in the form "Limit has been breached for {what}. Current usage is {usage}, limit is {limit} for period {period}.", and the root `error.message` is `Forbidden`. `LIMIT_BREACH` is the only entry in `innerErrors`: unlike a `400`, it is not followed by a `GENERATE_FUNCTION_FAILED` entry.

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

#### `500` — Generation failed because of a server-side error (`GENERATE_FUNCTION_FAILED`). No document was written to the delivery target. When the cause is known, a specific entry comes first and `GENERATE_FUNCTION_FAILED` follows it — for example `LOCALE_DOWNLOAD_FAILED` when the locale named in `document.locale` cannot be loaded, which is what an unrecognized locale code produces, or `TEMPLATE_READ_FAILED` when the template file named in `template.urn` cannot be read. The `innerErrors` entry carries an `eventId` when the failure was logged — 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.