Upload Template

The upload template endpoint allows you to upload a Word document template that can be used to generate documents.

Request

POST /v1/templates

Request Body

The request must be sent as multipart/form-data with the following fields:

FieldTypeDescription
namestringThe name of the template file (must end with .docx)
filefileThe Word document template file (max 10MB)

Response

{
  "id": string
}

Response Fields

FieldTypeDescription
idstringThe unique identifier of the uploaded template

Examples

import { readFileSync } from 'fs';

const apiKey = "Your_API_Key";

const file = readFileSync('template.docx');   
const blob = new Blob([file]);

const formData = new FormData();
formData.append('name', 'template.docx');
formData.append('file', blob);

const response = await fetch('https://templatedocs.io/api/v1/templates', {
    method: 'POST',
    headers: {
        "Authorization": `Bearer ${apiKey}`
    },
    body: formData
});

const data = await response.json();
console.log('Template ID:', data.id);

Error Responses

The endpoint returns errors in the standard error format with optional details:

{
  error: {
    status: number,
    message: string,
    details?: {
      type: "Message",
      message: string
    }[]
  }
}

Example Error Response

{
  "error": {
    "status": 400,
    "message": "Template validation errors",
    "details": [
      {
        "type": "Message",
        "message": "Template contains no tags"
      }
    ]
  }
}