Skip to content

Templates and JSON

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

Open Templates in the workspace 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.

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.

invoice-data.json
{
"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.

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

Terminal
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.

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.

Use the API reference for supported request fields and the PDFShift comparison for migration considerations. Test the supplied examples against your deployment before migrating production documents.

Use the document assistant to propose and inspect a structured draft from instructions, branding and sample JSON. Review and explicitly publish the resulting template before using it for repeat generation.