Templates API
Create, read, update, and delete document templates via the API.
Overview
Templates define the structure and design of your generated documents. You can manage templates through the dashboard visual editor or programmatically via the API.
GET /v1/templates GET /v1/templates/:id POST /v1/templates PATCH /v1/templates/:id DELETE /v1/templates/:id
List Templates
GET
/v1/templatesReturns a paginated list of all templates in your account.
Query Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
limit | integer | 20 | Number of results per page (1-100) |
cursor | string | - | Pagination cursor from previous response |
status | string | - | Filter by status: active, draft, archived |
Response
{
"data": [
{
"id": "tpl_invoice_basic",
"name": "Basic Invoice",
"description": "A simple invoice template",
"status": "active",
"version": 3,
"created_at": "2024-01-10T08:00:00Z",
"updated_at": "2024-01-15T14:30:00Z"
},
{
"id": "tpl_contract_nda",
"name": "NDA Contract",
"description": "Non-disclosure agreement template",
"status": "active",
"version": 1,
"created_at": "2024-01-12T10:00:00Z",
"updated_at": "2024-01-12T10:00:00Z"
}
],
"pagination": {
"has_more": true,
"next_cursor": "eyJpZCI6InRwbF9jb250cmFjdF9uZGEifQ",
"total_count": 15
}
}
Example
curl https://api.shablonix.com/v1/templates?limit=10&status=active \
-H "Authorization: Bearer tf_live_your_api_key"
Get Template
GET
/v1/templates/:idRetrieves the details of a specific template including its full schema.
Response
{
"id": "tpl_invoice_basic",
"name": "Basic Invoice",
"description": "A simple invoice template",
"status": "active",
"version": 3,
"schema": {
"fields": [
{
"name": "company_name",
"type": "string",
"required": true
},
{
"name": "invoice_number",
"type": "string",
"required": true
},
{
"name": "items",
"type": "array",
"items": {
"type": "object",
"properties": {
"description": { "type": "string" },
"quantity": { "type": "number" },
"unit_price": { "type": "number" }
}
}
}
]
},
"default_options": {
"page_size": "letter",
"orientation": "portrait"
},
"created_at": "2024-01-10T08:00:00Z",
"updated_at": "2024-01-15T14:30:00Z"
}
Example
curl https://api.shablonix.com/v1/templates/tpl_invoice_basic \
-H "Authorization: Bearer tf_live_your_api_key"
Create Template
POST
/v1/templatesCreates a new template with the provided configuration.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Template display name |
html | string | Yes | HTML template with data bindings |
css | string | No | Custom CSS styles |
description | string | No | Template description |
schema | object | No | Data schema for validation |
default_options | object | No | Default PDF generation options |
Example
curl -X POST https://api.shablonix.com/v1/templates \
-H "Authorization: Bearer tf_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"name": "Receipt Template",
"description": "Simple receipt for purchases",
"html": "<div class=\"receipt\"><h1>Receipt</h1><p>Order: {{order_number}}</p><p>Amount: {{currency}}{{amount}}</p><p>Date: {{date}}</p></div>",
"css": ".receipt { font-family: Arial, sans-serif; padding: 20px; }",
"schema": {
"fields": [
{ "name": "order_number", "type": "string", "required": true },
{ "name": "amount", "type": "number", "required": true },
{ "name": "currency", "type": "string", "default": "$" },
{ "name": "date", "type": "string", "required": true }
]
},
"default_options": {
"page_size": "a5",
"orientation": "portrait"
}
}'
Update Template
PATCH
/v1/templates/:idUpdates an existing template. Only provided fields will be updated. A new version is created for each update.
Versioning
Each update creates a new template version. Previously generated documents are not affected
by template updates.
Example
curl -X PATCH https://api.shablonix.com/v1/templates/tpl_receipt \
-H "Authorization: Bearer tf_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"name": "Receipt Template v2",
"description": "Updated receipt with tax support",
"html": "<div class=\"receipt\"><h1>Receipt</h1><p>Order: {{order_number}}</p><p>Subtotal: {{currency}}{{subtotal}}</p><p>Tax: {{currency}}{{tax}}</p><p>Total: {{currency}}{{total}}</p></div>"
}'
Delete Template
DELETE
/v1/templates/:idDeletes a template. This action is irreversible.
Caution
Deleting a template does not affect previously generated documents, but you will no longer
be able to generate new documents with this template.
Example
curl -X DELETE https://api.shablonix.com/v1/templates/tpl_receipt \
-H "Authorization: Bearer tf_live_your_api_key"
Response
{
"id": "tpl_receipt",
"deleted": true
}
Template Schema
Define a schema to validate data passed to your templates and provide better error messages:
{
"schema": {
"fields": [
{
"name": "customer_name",
"type": "string",
"required": true,
"description": "Full name of the customer"
},
{
"name": "email",
"type": "string",
"required": true,
"format": "email"
},
{
"name": "quantity",
"type": "number",
"required": true,
"min": 1,
"max": 1000
},
{
"name": "items",
"type": "array",
"required": true,
"minItems": 1,
"items": {
"type": "object",
"properties": {
"name": { "type": "string", "required": true },
"price": { "type": "number", "required": true },
"quantity": { "type": "number", "default": 1 }
}
}
},
{
"name": "notes",
"type": "string",
"required": false,
"default": ""
}
]
}
}
Supported Types
| Type | Validation Options |
|---|---|
string | minLength, maxLength, pattern, format (email, url, date) |
number | min, max, integer |
boolean | - |
array | minItems, maxItems, items (nested schema) |
object | properties (nested schema) |