Skip to main content

Templates API

Manage document templates (PDF/Excel) programmatically.

Endpoints Overview

MethodEndpointDescription
POST/api/templatesCreate new template
GET/api/templates/:idGet template by ID
PUT/api/templates/:idUpdate template
DELETE/api/templates/:idDelete template (soft delete)
POST/api/templates/:id/publishPublish template
POST/api/templates/:id/duplicateDuplicate template
GET/api/templates/:id/exportExport template to JSON
POST/api/templates/importImport template from JSON
GET/api/templates/:id/versionsList template versions
GET/api/templates/:id/versions/:versionIdGet specific version
POST/api/templates/:id/versions/:versionId/restoreRestore to version
POST/api/templates/:id/previewPreview template
GET/api/templates/:id/analyticsGet template analytics
GET/api/templates/:id/zapier-fieldsGet Zapier field definitions
POST/api/templates/:type/:id/shareShare template
GET/api/templates/:type/:id/sharesList template shares
GET/api/templates/sharedGet shared templates
PUT/api/templates/shares/:shareIdUpdate share permissions
DELETE/api/templates/shares/:shareIdRevoke share
POST/api/templates/bulk-deleteBulk delete templates
POST/api/templates/bulk-categoriesBulk assign categories
POST/api/templates/validate-schemaValidate schema
POST/api/templates/validate-variablesValidate 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

FieldTypeRequiredDescription
namestringYesTemplate name
descriptionstringNoTemplate description
outputFormatsarrayYesOutput formats: ["pdf"], ["xlsx"], or ["pdf", "xlsx"]
schemaobjectYesTemplate schema (see Template Schema)
variablesarrayNoTemplate variables
constantsobjectNoConstant values
calculatedVariablesarrayNoCalculated variables with expressions
folderIdstringNoFolder 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

ParameterTypeDescription
idstringTemplate 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

ParameterTypeDescription
idstringTemplate ID, shortId, or slug

Request Body

FieldTypeRequiredDescription
namestringNoTemplate name
descriptionstringNoTemplate description
schemaobjectNoUpdated template schema
variablesarrayNoUpdated variables
constantsobjectNoUpdated constants
calculatedVariablesarrayNoUpdated calculated variables
folderIdstringNoMove to folder

Response

Returns the updated template object.


Delete Template

DELETE /api/templates/:id

Soft delete a template.

Path Parameters

ParameterTypeDescription
idstringTemplate 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

ParameterTypeDescription
idstringTemplate ID

Request Body

FieldTypeRequiredDescription
releaseNotesstringNoVersion 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

ParameterTypeDescription
idstringTemplate 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

ParameterTypeDescription
idstringTemplate 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:

FieldTypeRequiredDescription
filefileYesJSON file to import
duplicateHandlingstringNoConflict 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.

Path Parameters

ParameterTypeDescription
idstringTemplate ID

Response

[
{
"id": "ver_abc123",
"version": 2,
"releaseNotes": "Updated layout",
"publishedAt": "2025-01-15T10:00:00Z",
"publishedBy": "John Doe"
},
{
"id": "ver_xyz789",
"version": 1,
"releaseNotes": "Initial version",
"publishedAt": "2025-01-01T00:00:00Z",
"publishedBy": "John Doe"
}
]

Get Template Version

GET /api/templates/:id/versions/:versionId

Get a specific version of a template.

Path Parameters

ParameterTypeDescription
idstringTemplate ID
versionIdstringVersion ID

Response

Returns the complete template state at that version.


Restore Template Version

POST /api/templates/:id/versions/:versionId/restore

Restore a template to a previous version.

Path Parameters

ParameterTypeDescription
idstringTemplate ID
versionIdstringVersion ID to restore

Request Body

FieldTypeRequiredDescription
releaseNotesstringNoNotes for the restore

Response

{
"success": true,
"newVersion": 3,
"message": "Template restored to version 1"
}

Preview Template

POST /api/templates/:id/preview

Generate a preview of the template with sample data.

Path Parameters

ParameterTypeDescription
idstringTemplate ID

Request Body

FieldTypeRequiredDescription
variablesobjectNoVariable values for preview
formatstringNoOutput format: pdf or xlsx (default: pdf)

Response

Returns binary PDF or Excel file data.


Get Template Analytics

GET /api/templates/:id/analytics

Get usage analytics for a specific template.

Path Parameters

ParameterTypeDescription
idstringTemplate ID

Query Parameters

ParameterTypeDefaultDescription
startDatestring-Start date (ISO 8601)
endDatestring-End date (ISO 8601)
periodstring30dPeriod: 7d, 30d, 90d, 1y

Response

{
"templateId": "tmpl_abc123",
"templateName": "Invoice Template",
"usage": {
"total": 450,
"last7Days": 45,
"last30Days": 180
},
"performance": {
"successRate": 99.1,
"avgGenerationTimeMs": 2300,
"failedCount": 4
},
"trend": [
{ "date": "2025-01-01", "count": 15 },
{ "date": "2025-01-02", "count": 18 }
]
}

Get Zapier Fields

GET /api/templates/:id/zapier-fields

Get template variables in Zapier-compatible field format for integration.

Path Parameters

ParameterTypeDescription
idstringTemplate ID, shortId, or slug

Response

{
"fields": [
{
"key": "invoiceNumber",
"label": "Invoice Number",
"type": "string",
"required": true
},
{
"key": "lineItems",
"label": "Line Items",
"type": "array",
"children": [
{ "key": "description", "label": "Description", "type": "string" },
{ "key": "quantity", "label": "Quantity", "type": "number" },
{ "key": "price", "label": "Price", "type": "number" }
]
}
]
}

Share Template

POST /api/templates/:type/:id/share

Share a template with another team.

Path Parameters

ParameterTypeDescription
typestringTemplate type: email or attachment
idstringTemplate ID

Request Body

FieldTypeRequiredDescription
targetTeamIdstringYesTeam ID to share with
permissionstringNoPermission level: view or edit (default: view)

Response

{
"id": "share_abc123",
"templateId": "tmpl_xyz789",
"targetTeamId": "team_123",
"permission": "view",
"createdAt": "2025-01-15T00:00:00Z"
}

List Template Shares

GET /api/templates/:type/:id/shares

Get all shares for a template.

Path Parameters

ParameterTypeDescription
typestringTemplate type: email or attachment
idstringTemplate ID

Response

{
"shares": [
{
"id": "share_abc123",
"targetTeamId": "team_123",
"targetTeamName": "Partner Company",
"permission": "view",
"createdAt": "2025-01-15T00:00:00Z"
}
]
}

Get Shared Templates

GET /api/templates/shared

Get templates that have been shared with your team.

Response

{
"templates": [
{
"id": "tmpl_abc123",
"name": "Invoice Template",
"ownerTeamName": "Acme Corp",
"permission": "view",
"sharedAt": "2025-01-15T00:00:00Z"
}
]
}

Update Share

PUT /api/templates/shares/:shareId

Update share permissions.

Path Parameters

ParameterTypeDescription
shareIdstringShare ID

Request Body

FieldTypeRequiredDescription
permissionstringYesNew permission: view or edit

Response

Returns the updated share object.


Revoke Share

DELETE /api/templates/shares/:shareId

Revoke a template share.

Path Parameters

ParameterTypeDescription
shareIdstringShare ID

Response

{
"success": true,
"message": "Share revoked successfully"
}

Bulk Delete Templates

POST /api/templates/bulk-delete

Delete multiple templates at once.

Request Body

FieldTypeRequiredDescription
idsarrayYesArray of template IDs to delete

Response

{
"deleted": 3,
"skipped": 1,
"errors": [
{ "id": "tmpl_xyz", "reason": "Template not found" }
]
}

Bulk Assign Categories

POST /api/templates/bulk-categories

Assign categories to multiple templates.

Request Body

FieldTypeRequiredDescription
templateIdsarrayYesTemplate IDs
categoryIdsarrayYesCategory IDs to assign
modestringNoMode: add or replace (default: add)

Response

{
"updated": 5,
"skipped": 0
}

Validate Schema

POST /api/templates/validate-schema

Validate a template schema without saving.

Request Body

FieldTypeRequiredDescription
templateTypestringYesType: email or attachment
schemaobjectYesSchema to validate

Response

{
"valid": true,
"errors": [],
"warnings": [
{ "path": "sections[0].components[2]", "message": "Image source is empty" }
]
}

Validate Variables

POST /api/templates/validate-variables

Validate template variables without saving.

Request Body

FieldTypeRequiredDescription
variablesarrayYesVariables array to validate
constantsobjectNoConstants to validate
calculatedVariablesarrayNoCalculated variables to validate

Response

{
"valid": true,
"errors": [],
"warnings": []
}

Attachment Templates

For legacy compatibility, attachment template endpoints are also available at /api/templates/attachment/*:

MethodEndpointMaps to
POST/api/templates/attachmentCreate template
GET/api/templates/attachmentList templates
GET/api/templates/attachment/:idGet template
PUT/api/templates/attachment/:idUpdate template
DELETE/api/templates/attachment/:idDelete template
POST/api/templates/attachment/:id/publishPublish template
GET/api/templates/attachment/:id/exportExport template
POST/api/templates/attachment/importImport template
GET/api/templates/attachment/:id/versionsList versions
GET/api/templates/attachment/:id/versions/:versionIdGet version
POST/api/templates/attachment/:id/versions/:versionId/restoreRestore version
POST/api/templates/attachment/:id/previewPreview template

Error Codes

Template Errors (ERR_TMPL_xxx)

CodeDescription
ERR_TMPL_001Template not found
ERR_TMPL_002Document template not found
ERR_TMPL_003Attachment template not found
ERR_TMPL_004You do not have permission to access this template
ERR_TMPL_005You do not have permission to edit this template
ERR_TMPL_006You do not have permission to delete this template
ERR_TMPL_007You do not have permission to view this template
ERR_TMPL_008Template schema validation failed
ERR_TMPL_009Invalid template type
ERR_TMPL_010Template import data is invalid
ERR_TMPL_011Template with the same name already exists
ERR_TMPL_012Template export failed
ERR_TMPL_013Template version not found
ERR_TMPL_014Version does not belong to this template
ERR_TMPL_015No file uploaded for template import
ERR_TMPL_016Invalid JSON file format
ERR_TMPL_020No draft version available to publish
ERR_TMPL_021Template has no published version
ERR_TMPL_022Template has no draft version
ERR_TMPL_023Invalid version parameter

Sharing Errors (ERR_SHARE_xxx)

CodeDescription
ERR_SHARE_001Share not found
ERR_SHARE_002Template is already shared with this team
ERR_SHARE_003Cannot share template with your own team
ERR_SHARE_004Target team not found
ERR_SHARE_005You do not have permission to share this template

Related: Documents API | Template Schema | Analytics API