> ## Documentation Index
> Fetch the complete documentation index at: https://pdfbase.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a template

> Store a reusable HTML template with a data schema for repeated rendering.

## Phase

**Phase 1 (Launch)**

## Request

<ParamField body="name" type="string" required>
  Human-readable name for the template. Must be unique within your account. Used as the identifier in CLI commands (`pdfbase templates push`).
</ParamField>

<ParamField body="html" type="string" required>
  HTML content with Handlebars placeholders for dynamic data. Supports `{{variable}}`, `{{#each items}}`, `{{#if condition}}`, and all standard Handlebars helpers.
</ParamField>

<ParamField body="css" type="string">
  CSS stylesheet applied to the template. Kept separate from HTML for cleaner template management.
</ParamField>

<ParamField body="schema" type="object" required>
  JSON Schema defining the expected data shape. PDFBase validates render requests against this schema and returns `422` on mismatch.

  Supported types: `string`, `number`, `boolean`, `date`, `array`, `object`.
</ParamField>

<ParamField body="defaults" type="object">
  Default rendering options applied every time this template is rendered. Can be overridden per-render.

  * `format` (string) — Page size
  * `margin` (string | object) — Margins
  * `landscape` (boolean) — Orientation
  * `header` (object) — Header HTML
  * `footer` (object) — Footer HTML
  * `compress` (string) — Compression level
</ParamField>

<ParamField body="sample_data" type="object">
  Example data that satisfies the schema. Used by the CLI's `preview` command and the dashboard's template preview.
</ParamField>

<ParamField body="description" type="string">
  Optional description shown in the dashboard and CLI listings.
</ParamField>

## Response

```json theme={null}
{
  "id": "tpl_abc123",
  "object": "template",
  "name": "invoice",
  "description": "Standard customer invoice",
  "schema": {
    "number": "string",
    "customer": "string",
    "items": "array",
    "due_date": "date",
    "total": "string"
  },
  "defaults": {
    "format": "a4",
    "margin": "20mm",
    "compress": "medium"
  },
  "version": 1,
  "created_at": "2026-05-19T10:00:00Z",
  "updated_at": "2026-05-19T10:00:00Z"
}
```

<ResponseField name="version" type="integer">
  Auto-incrementing version number. Starts at 1, increments on every `PATCH` update. Useful for tracking which version of a template generated a specific PDF.
</ResponseField>

## Example

```bash theme={null}
curl -X POST https://api.pdfbase.dev/v1/templates \
  -H "Authorization: Bearer pk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "invoice",
    "description": "Standard customer invoice",
    "html": "<!DOCTYPE html><html><head><style>body { font-family: Inter, sans-serif; } table { width: 100%; border-collapse: collapse; } th, td { padding: 8px; text-align: left; border-bottom: 1px solid #eee; }</style></head><body><h1>Invoice #{{number}}</h1><p>Bill to: {{customer}}</p><table><thead><tr><th>Item</th><th>Qty</th><th>Price</th></tr></thead><tbody>{{#each items}}<tr><td>{{this.name}}</td><td>{{this.qty}}</td><td>{{this.price}}</td></tr>{{/each}}</tbody></table><p><strong>Total: {{total}}</strong></p><p>Due: {{due_date}}</p></body></html>",
    "schema": {
      "number": "string",
      "customer": "string",
      "items": "array",
      "due_date": "date",
      "total": "string"
    },
    "defaults": {
      "format": "a4",
      "margin": "20mm",
      "compress": "medium"
    },
    "sample_data": {
      "number": "INV-001",
      "customer": "Acme Corp",
      "items": [
        { "name": "Widget", "qty": 10, "price": "$50.00" },
        { "name": "Gadget", "qty": 5, "price": "$75.00" }
      ],
      "due_date": "2026-06-19",
      "total": "$875.00"
    }
  }'
```
