---
title: "Create Document Template"
method: POST
path: "/document_generation/template-create"
tags: ["Document AI — DMS"]
---

# Create Document Template

`POST /document_generation/template-create`

## Request

- Base URL: `https://api.paperoffice.ai/latest`
- URL: `https://api.paperoffice.ai/latest/document_generation/template-create`
- Auth: HTTP bearer

Create a reusable document generation template (HTML with {{placeholder}} merge fields) for po_documents_create_from_template.

## Request body

- object
  - `template_id` string: Optional template ID (auto-generated from name when omitted).
  - `name` string, required: Display name for the template.
  - `html_content` string, required: HTML body with {{variable}} placeholders for merge fields (max 5 MB).
  - `description` string: Optional template description.
  - `category` string: Category (e.g. invoices, contracts, reports).
  - `variables_schema` object: Schema of expected template variables; fields in its required list must be present and non-empty when generating.
  - `page_format` string: Page size (A4, A3, A5, Letter, Legal).
  - `page_orientation` 'portrait' | 'landscape': Page orientation: portrait or landscape.
  - `margin_top` integer: Top page margin in millimeters.
  - `margin_right` integer: Right page margin in millimeters.
  - `margin_bottom` integer: Bottom page margin in millimeters.
  - `margin_left` integer: Left page margin in millimeters.
  - `header_html` string: HTML rendered at the top of each page (max 512 KB).
  - `footer_html` string: HTML rendered at the bottom of each page (max 512 KB).
  - `engine` 'hbs_v2' | 'po_regex_v1': Corporate plan and above: Template engine: hbs_v2 (conditions, loops, paths, locale helpers) or po_regex_v1 (legacy).
  - `custom_css` string: Corporate plan and above: CSS for the document (url() and @import are removed).
  - `sample_data` object: Corporate plan and above: Sample variables for preview and validation.
  - `locale_default` string: Corporate plan and above: Default locale (e.g. de_DE).
  - `title_pattern` string: Corporate plan and above: Default document title with placeholders.
  - `image_data` string: Corporate plan and above: Template image for the app: https URL or PNG/JPEG/WebP/SVG data URI (max 2 MB); empty string removes it.
  - `change_note` string: Corporate plan and above: Note stored with version 1.

## Response `200`

Success

- SuccessEnvelope: Success envelope. Payload fields are endpoint-specific (top-level fields, `result`/`job_result` for jobs, `data` on some account endpoints).
  - `status` 'success', required
  - `processing_time` union
    - string
    - number
  - `_billing` object

## Other responses

- `201`: Created
- `4XX`: Error
- `5XX`: Error

---

[API](https://skmtc.dev/paperoffice/apis/paperoffice-ai-api.md) · [All operations](https://skmtc.dev/paperoffice/apis/paperoffice-ai-api/llms.txt) · [OpenAPI document](https://skmtc.dev/paperoffice/apis/paperoffice-ai-api/revisions/c6a6228a4509?raw)
