---
title: "Replace the draft sources"
method: PUT
path: "/v1/templates/{template_id}/draft"
tags: ["Templates"]
---

# Replace the draft sources

`PUT /v1/templates/{template_id}/draft`

## Request

- Base URL: `https://api-eu.dynamicdocumentapi.com`
- URL: `https://api-eu.dynamicdocumentapi.com/v1/templates/{template_id}/draft`
- Auth: one of:
  - HTTP bearer
  - API key in header `X-API-Key`

Replaces the draft with the content fields of the template's type (see `POST /v1/templates`) or one `content` object. Send `If-Match: <revision>` (the `revision` of the draft you edited) to detect concurrent edits; a stale revision answers `409 draft_revision_conflict`. The response carries the new revision in `ETag`. `image_canvas` drafts are compiled when published — and by `version: draft` renders, which answer `422` with JSON pointers under `/template/draft` when the draft does not compile.

## Path parameters

- `template_id` string, required

## Headers

- `If-Match` string

## Request body

- union: `PUT /v1/templates/{id}/draft`: the content fields of the template's type, or one `content` object.
  - PdfCodeDraftWrite
    - `content` object: The whole content in one object, instead of the separate fields.
    - `head` string: Extra `<head>` markup (styles, fonts).
    - `header_footer` object: `{header, footer}`: header/footer objects as in `PdfOptions`.
    - `html` string: Jinja HTML of the body.
    - `options` object: Default output options (`RenderOptions`: `output_format`, `filename`, `pdf` as in `PdfOptions`, `image`, `strict_undefined`, and for PDF templates `einvoice: {profile, invoice_path}`, a default hybrid e-invoice that every render embeds unless the request sends `output.einvoice`).
    - `schema` object, nullable
  - PdfMarkdownDraftWrite
    - `content` object: The whole content in one object, instead of the separate fields.
    - `css` string
    - `head` string
    - `header_footer` object: `{header, footer}`: header/footer objects as in `PdfOptions`.
    - `markdown` string: Jinja-enabled Markdown.
    - `options` object: Default output options (`RenderOptions`: `output_format`, `filename`, `pdf` as in `PdfOptions`, `image`, `strict_undefined`, and for PDF templates `einvoice: {profile, invoice_path}`, a default hybrid e-invoice that every render embeds unless the request sends `output.einvoice`).
    - `schema` object, nullable
    - `theme` string: `default`, `github`, `academic`, `minimal` or `none`.
  - ImageCanvasDraftWrite
    - `content` object: The whole content in one object, instead of the separate fields.
    - `options` object: Default output options (`RenderOptions`: `output_format`, `filename`, `pdf` as in `PdfOptions`, `image`, `strict_undefined`, and for PDF templates `einvoice: {profile, invoice_path}`, a default hybrid e-invoice that every render embeds unless the request sends `output.einvoice`).
    - `scene` object: The canvas scene as defined by `@dynamic-document-api/scene-schema`.
    - `schema` object, nullable

## Response `200`

Saved. `ETag` holds the new revision.

- TemplateDraft
  - `content` object, required: The content of the template's type: `html`/`head`, `markdown`, `doc`/`theme`, `scene`, and `options`.
  - `object` string
  - `revision` integer, required: Send it back as `If-Match` on the next write.
  - `schema` object, nullable, required
  - `template_id` string, required
  - `updated_at` string, date-time, required

## Other responses

- `400`: Invalid request body (`errors[]` with JSON pointers).
- `401`: Missing, invalid, expired or revoked credentials.
- `403`: Insufficient scope, IP not allowed, workspace suspended or scheduled for deletion, or email not verified.
- `404`: Template not found.
- `409`: The draft changed since the revision in `If-Match` (`draft_revision_conflict`).
- `410`: Template deleted.
- `423`: The template is locked (`template_locked`); Owners and Admins unlock it in the dashboard.
- `429`: Rate limited (`Retry-After`).
- `503`: The control plane is unreachable (`Retry-After`).

---

[API](https://skmtc.dev/dynamicdocumentapi/apis/dynamic-document-api.md) · [All operations](https://skmtc.dev/dynamicdocumentapi/apis/dynamic-document-api/llms.txt) · [OpenAPI document](https://skmtc.dev/dynamicdocumentapi/apis/dynamic-document-api/revisions/0f14bc0000f4?raw)
