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:
| Field | Type | Description |
|---|---|---|
name | string | The name of the template file (must end with .docx) |
file | file | The Word document template file (max 10MB) |
Each stored template consumes one template quota unit.
Response
On success, the endpoint returns the uploaded template metadata.
See the GET Template endpoint response description for more
information on the TemplateMetadata type.
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"
}
]
}
}