Templates API
Manage document templates (PDF/Excel) programmatically.
Endpoints Overview
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/templates | Create new template |
| GET | /api/templates/:id | Get template by ID |
| PUT | /api/templates/:id | Update template |
| DELETE | /api/templates/:id | Delete template (soft delete) |
| POST | /api/templates/:id/publish | Publish template |
| POST | /api/templates/:id/duplicate | Duplicate template |
| GET | /api/templates/:id/export | Export template to JSON |
| POST | /api/templates/import | Import template from JSON |
| GET | /api/templates/:id/versions | List template versions |
| GET | /api/templates/:id/versions/:versionId | Get specific version |
| POST | /api/templates/:id/versions/:versionId/restore | Restore to version |
| POST | /api/templates/:id/preview | Preview template |
| GET | /api/templates/:id/analytics | Get template analytics |
| GET | /api/templates/:id/zapier-fields | Get Zapier field definitions |
| POST | /api/templates/:type/:id/share | Share template |
| GET | /api/templates/:type/:id/shares | List template shares |
| GET | /api/templates/shared | Get shared templates |
| PUT | /api/templates/shares/:shareId | Update share permissions |
| DELETE | /api/templates/shares/:shareId | Revoke share |
| POST | /api/templates/bulk-delete | Bulk delete templates |
| POST | /api/templates/bulk-categories | Bulk assign categories |
| POST | /api/templates/validate-schema | Validate schema |
| POST | /api/templates/validate-variables | Validate variables |
note
All endpoints require JWT authentication. API key authentication is supported for read operations.
Create Template
POST /api/templates
Create a new document template.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Template name |
description | string | No | Template description |
outputFormats | array | Yes | Output formats: ["pdf"], ["xlsx"], or ["pdf", "xlsx"] |
schema | object | Yes | Template schema (see Template Schema) |
variables | array | No | Template variables |
constants | object | No | Constant values |
calculatedVariables | array | No | Calculated variables with expressions |
folderId | string | No | Folder ID to place template in |
Request Example
{
"name": "Invoice Template",
"description": "Professional invoice with line items",
"outputFormats": ["pdf"],
"schema": {
"format": "pdf",
"pageSize": "A4",
"sections": [
{
"id": "header",
"components": [
{
"type": "text",
"props": {
"content": "Invoice #{{invoiceNumber}}"
}
}
]
}
]
},
"variables": [
{
"name": "invoiceNumber",
"type": "string",
"required": true,
"defaultValue": "INV-001"
}
]
}
Response
{
"id": "tmpl_abc123",
"shortId": "etpl_a1b2c3d4",
"slug": "invoice-template",
"name": "Invoice Template",
"outputFormats": ["pdf"],
"createdAt": "2025-01-15T00:00:00Z"
}
Get Template
GET /api/templates/:id
Get a template by ID, shortId, or slug.
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | Template ID, shortId (etpl_xxx), or slug |
Response
{
"id": "tmpl_abc123",
"shortId": "etpl_a1b2c3d4",
"slug": "invoice-template",
"name": "Invoice Template",
"description": "Professional invoice with line items",
"outputFormats": ["pdf"],
"schema": {
"sections": [...],
"format": "pdf"
},
"variables": [
{
"name": "invoiceNumber",
"type": "string",
"required": true
}
],
"constants": {},
"calculatedVariables": [],
"isPublished": true,
"publishedAt": "2025-01-15T10:00:00Z",
"createdAt": "2025-01-01T00:00:00Z",
"updatedAt": "2025-01-15T00:00:00Z"
}
Update Template
PUT /api/templates/:id
Update a template.
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | Template ID, shortId, or slug |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
name | string | No | Template name |
description | string | No | Template description |
schema | object | No | Updated template schema |
variables | array | No | Updated variables |
constants | object | No | Updated constants |
calculatedVariables | array | No | Updated calculated variables |
folderId | string | No | Move to folder |
Response
Returns the updated template object.
Delete Template
DELETE /api/templates/:id
Soft delete a template.
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | Template ID, shortId, or slug |
Response
{
"success": true,
"message": "Template deleted successfully"
}
Publish Template
POST /api/templates/:id/publish
Publish a template, creating a new version that can be used for document generation.
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | Template ID |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
releaseNotes | string | No | Version release notes |
Response
{
"id": "tmpl_abc123",
"version": 2,
"publishedAt": "2025-01-15T10:00:00Z"
}
Duplicate Template
POST /api/templates/:id/duplicate
Create a copy of an existing template.
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | Template ID to duplicate |
Response
Returns the newly created template with "(Copy)" appended to the name.
Export Template
GET /api/templates/:id/export
Export a template to a JSON file for backup or sharing.
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | Template ID |
Response
Returns a JSON file download containing the complete template definition.
Import Template
POST /api/templates/import
Import a template from a JSON file.
Request
Multipart form data with:
| Field | Type | Required | Description |
|---|---|---|---|
file | file | Yes | JSON file to import |
duplicateHandling | string | No | Conflict strategy: rename, skip, or overwrite |
Response
{
"status": "success",
"templateId": "tmpl_abc123",
"message": "Template imported successfully"
}
List Template Versions
GET /api/templates/:id/versions
Get all published versions of a template.