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

# Templates and JSON

> Keep the layout in a published template and send just the data that changes between documents.

## Create a draft

Open **Templates** in the [workspace](https://dockiln.io/app) and choose a starter, such as Invoice, Quote, Certificate or Shipping label. Edit the layout alongside the sample data and preview. **Save** updates the draft. **Publish** creates an immutable numbered version that generation requests can use.

For the API equivalent, `GET /v1/library` returns starter definitions. Submit a complete definition as the JSON body of `POST /v1/templates`. Save later edits with `PUT /v1/templates/{id}` and publish with `POST /v1/templates/{id}/publish`. The create and save operations receive the definition itself. The create response includes the new template ID.

## Map fields and repeat rows

The Invoice starter reads the recipient from `{{recipient.name}}`, the total from `{{total}}` and table rows from `items`. Its three column mappings are `field1`, `field2` and `field3`, relative to each item.

```json title="invoice-data.json" theme={null}
{
  "recipient": { "name": "Aster Studio" },
  "items": [
    { "field1": "Design review", "field2": "2", "field3": "$300.00" },
    { "field1": "Print proof", "field2": "1", "field3": "$40.00" }
  ],
  "total": "$340.00"
}
```

Send the formatted amounts you want printed. DocKiln interpolates scalar values and does not calculate totals. A supplied repeating-table path must resolve to an array. A structured document supports up to 500 rows and eight columns. On multipage PDFs the table header repeats.

## Generate from a published version

Save the data above as `invoice-data.json`. Set `TEMPLATE_ID` to the published Invoice template and submit version 1:

```bash title="Terminal" theme={null}
jq -n --arg id "$TEMPLATE_ID" --slurpfile data invoice-data.json \
  '{templateId: $id, version: 1, data: $data[0]}' |
  curl --fail-with-body -sS "$DOCKILN_URL/v1/documents" \
    -H "Authorization: Bearer $DOCKILN_API_KEY" \
    -H "Content-Type: application/json" --data-binary @-
```

Omit `version` to use the current publication. Omit `data` to use that version's sample. The job stores a snapshot when accepted. Subsequent draft changes or publications cannot change that job.

## Coordinate concurrent edits

Read the template's `updated` value. Send it in the `If-Unmodified-Since-Version` header on save or publish. A stale value returns **409**. Reload the draft and review the competing edits before trying again. `GET /v1/templates/{id}/versions` lists the published definitions.

## HTML templates in the review build

The 1.1 review build also accepts HTML templates with escaped data slots, iteration, conditions, stable slugs and immutable published versions. [See the HTML template example](https://docs.dockiln.io/pdfshift-migration.md#reuse-html-with-json-data).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.