---
title: "Validate & Generate Documents from Templates"
slug: validate-generate-documents-from-templates
url: https://apyhub.com/callable-labs/service/validate-generate-documents-from-templates
provider: Callable Labs
tags: [document-generation, template-rendering, docx, html-to-pdf, markdown-to-html]
auth: api_key
version: v1
service_type: sync
endpoints: 3
atoms: 30-250
mcp: true
---

# Validate & Generate Documents from Templates

Validate DOCX templates and render DOCX, HTML, or PDF from JSON data. Get variable checks, syntax errors, and generated document output.

## Endpoints

| Method | URL | Description | Atoms |
| --- | --- | --- | --- |
| POST | `https://api.eu.apyhub.com/callable-labs/validate-generate-documents-from-templates/v1/documents/validate` | What it does Validates a .docx template and checks it against optional input data. It returns wheth… | 30 |
| POST | `https://api.eu.apyhub.com/callable-labs/validate-generate-documents-from-templates/v1/documents/render` | What it does Fills a DOCX template using the values you provide in the request body. The endpoint c… | 250 |
| POST | `https://api.eu.apyhub.com/callable-labs/validate-generate-documents-from-templates/v1/documents/html` | What it does Renders a Jinja2 template from template using the values in data, with optional stylin… | 150 |

## Endpoint reference

### Validate a DOCX template

`POST https://api.eu.apyhub.com/callable-labs/validate-generate-documents-from-templates/v1/documents/validate` · 30 atoms · accepts `multipart/form-data` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `data` | body | string | no | Optional JSON object to check against the template's variables |
| `template` | body | string (binary) | yes | The .docx template to inspect |

#### Quickstart

Validate a `.docx` template by uploading the template file and, optionally, a JSON string of template data.

```bash
curl -X POST "https://api.eu.apyhub.com/callable-labs/validate-generate-documents-from-templates/v1/documents/validate" \
  -H "apy-token: $APY_TOKEN" \
  -F "template=@/path/to/template.docx" \
  -F 'data={"name":"Ava","company":"ApyHub"}'
```

#### What you'll get back

Returns a JSON object with these top-level fields: `ok` boolean, `engine` string, `unused` array of strings, `undefined` array of strings, `variables` array of strings, and `syntax_errors` array of objects. `ok` is `false` when the template has syntax errors.

```json
{
  "ok": true,
  "engine": "docxtemplater",
  "unused": [],
  "undefined": [],
  "variables": ["name", "company"],
  "syntax_errors": []
}
```

### Fill a DOCX template

`POST https://api.eu.apyhub.com/callable-labs/validate-generate-documents-from-templates/v1/documents/render` · 250 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `data.logo` | body | string | no | Default: ``. |
| `data.note` | body | string | no | Default: `Paid`. |
| `data.intro` | body | string | no | Default: `Thank you for your order.`. |
| `data.items` | body | array of object | no |  |
| `data.items[].qty` | body | number | no | Default: `2`. |
| `data.items[].name` | body | string | no | Default: `Widget`. |
| `data.items[].price` | body | number | no | Default: `9.5`. |
| `data.number` | body | string | no | Default: `INV-2026-1042`. |
| `data.customer.name` | body | string | no | Default: `Ada`. |
| `format` | body | string | no | `docx` returns the filled document, `pdf` returns a PDF, `json` (default) returns the DOCX as a base64 data URI plus metadata. One of: json, docx, pdf. Default: `json`. |
| `download` | body | boolean | no | Send `Content-Disposition: attachment` so browsers save the file. Default: `false`. |
| `template_base64` | body | string | yes | The .docx template, base64-encoded (≤ 5 MiB decoded). Default: `UEsDBBQAAAAIAA6uMl2tUqWRlQEAAMoGAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbLWVTU/bQBCG7/0Vli8+IHtDDxWq4nAocCyRGkSvm/U4Wdgv7UwC+ffMOolV0VCHBi6RnJn… |

#### Quickstart

Render a DOCX template from base64 and return the rendered result in the default JSON format.

```bash
curl -X POST "https://api.eu.apyhub.com/callable-labs/validate-generate-documents-from-templates/v1/documents/render" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "template_base64": "UEsDBBQAAAAIA...",
    "data": {
      "customer": { "name": "Ada Lovelace" },
      "items": [
        { "name": "Widget", "qty": 2, "price": 9.5 }
      ]
    }
  }'
```

#### What you'll get back

Returns a JSON object with rendering metadata such as `bytes` (`integer`), `cache` (`"hit"` or `"miss"`), `pages` (`integer` or `null`), `engine` (`string`), `format` (`"docx"`, `"pdf"`, or `"html"`), `data_uri` (`string`), `warnings` (`array` of strings), `queued_ms` (`integer`), `render_ms` (`integer`), `media_type` (`string`), and `engine_version` (`string`).

```json
{
  "bytes": 12345,
  "cache": "miss",
  "pages": null,
  "engine": "libreoffice",
  "format": "docx",
  "data_uri": "data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,...",
  "warnings": [],
  "queued_ms": 12,
  "render_ms": 45,
  "media_type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
  "engine_version": "7.6.0"
}
```

### Render an HTML or Markdown template

`POST https://api.eu.apyhub.com/callable-labs/validate-generate-documents-from-templates/v1/documents/html` · 150 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `css` | body | any | no | Extra stylesheet appended to the document shell. External URLs are never fetched. |
| `data.name` | body | string | no | Default: `Ada`. |
| `page.size` | body | string | no | Paper size. One of: A4, Letter, Legal, A3, A5. Default: `A4`. |
| `page.margin_mm` | body | number | no | Uniform page margin in millimetres. Default: `18`. |
| `page.orientation` | body | string | no | Orientation One of: portrait, landscape. Default: `portrait`. |
| `title` | body | any | no | `<title>` of the document shell. |
| `format` | body | string | no | `html` or `pdf` return the bytes; `json` (default) returns the HTML as a data URI plus metadata. One of: json, html, pdf. Default: `pdf`. |
| `download` | body | boolean | no | Send `Content-Disposition: attachment` so browsers save the file. Default: `false`. |
| `markdown` | body | boolean | no | Treat the rendered template as Markdown (CommonMark + tables) and convert it to HTML. Default: `true`. |
| `template` | body | string | yes | Jinja2 template in HTML or Markdown (≤ 256 KiB). Values are HTML-escaped; use `{{ value \| safe }}` to insert markup on purpose. A fragment is wrapped in a document shell with consistent fonts; a full… |

#### Quickstart

Render a simple HTML template with the minimum required input.

```bash
curl -X POST "https://api.eu.apyhub.com/callable-labs/validate-generate-documents-from-templates/v1/documents/html" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "<h1>Hello {{ name }}</h1>",
    "data": {
      "name": "Ada"
    }
  }'
```

#### What you'll get back

Returns a JSON object with rendering metadata. Top-level fields include `bytes` (integer), `cache` (`hit` or `miss`), `pages` (integer or `null`), `engine` (string), `format` (`docx`, `pdf`, or `html`), `data_uri` (string), `warnings` (array of strings), `queued_ms` (integer), `render_ms` (integer), `media_type` (string), and `engine_version` (string).

```json
{
  "bytes": 1234,
  "cache": "miss",
  "pages": null,
  "engine": "render-html-template",
  "format": "html",
  "data_uri": "data:text/html;base64,PGgxPkhlbGxvIEFkYTwvaDE+",
  "warnings": [],
  "queued_ms": 12,
  "render_ms": 34,
  "media_type": "text/html",
  "engine_version": "1.0.0"
}
```

## About

## What it does
Document Template Renderer fills and validates DOCX, HTML, and Markdown templates from JSON data. Send a template plus the values it reads, and get back validation details, rendered HTML, or a filled document in DOCX or PDF format.

Use the DOCX validation endpoint to inspect a template before generation. It reports whether the template is syntactically valid and can return the variables it reads, missing keys from your data, unused keys, and syntax errors with line numbers. That makes it useful for catching broken invoice, contract, or report templates before they reach production.

Use the rendering endpoints when you need finished output from templated content. For DOCX templates, provide the template as base64 and optional `data`, `format`, and `download` settings. For HTML or Markdown templates, send `template`, optional `data`, `css`, `page`, `title`, `format`, `download`, and `markdown`. The response includes the rendered bytes or `data_uri`, plus metadata such as `bytes`, `media_type`, `engine`, `engine_version`, `format`, `warnings`, and timing fields.

Document Template Renderer fits workflows like automated invoice generation, customer letters, proposals, and report exports where the template structure is known and the final document needs to be generated consistently from application data.

## Usage

Base URL: `https://api.eu.apyhub.com` (default region — see
`GET https://apyhub.com/api/public/regions` for the rest).

Authenticate with an ApyHub API key in the `apy-token` header.
Full docs and a live playground: https://apyhub.com/callable-labs/service/validate-generate-documents-from-templates
