Manage Word document templates for mail merge and document generation within the Office Add-in.
---
https://app.datapublisher.io/api/word-templates
---
All endpoints require JWT authentication via Authorization: Bearer header.
---
The Word Templates API allows you to:
Supported Operations:
---
Upload a .docx file as a template.
Endpoint: POST /upload
Headers:
Authorization: Bearer
Content-Type: multipart/form-data
Form Data:
template: File (required) - .docx file
name: String (required) - Template name
description: String (optional) - Template description
category: String (optional) - Category (e.g., "reports", "letters", "invoices")
tags: String (optional) - Comma-separated tags
Request Example:
const formData = new FormData();
formData.append('template', templateFile);
formData.append('name', 'Sales Report Template');
formData.append('description', 'Quarterly sales report');
formData.append('category', 'reports');
formData.append('tags', 'sales,quarterly,report');
Response (200 OK):
{
"success": true,
"template": {
"id": "template-uuid",
"name": "Sales Report Template",
"description": "Quarterly sales report",
"fileName": "sales-report-template.docx",
"category": "reports",
"tags": ["sales", "quarterly", "report"],
"fileSize": 45678,
"uploadedAt": "2026-02-12T10:30:00Z"
},
"message": "Template uploaded successfully"
}
Error Responses:
400 Bad Request - Invalid file:
{
"error": "Only .docx files are allowed"
}
413 Payload Too Large - File too large:
{
"error": "File size exceeds 10MB limit"
}
---
Get all Word templates for the user.
Endpoint: GET /
Headers:
Authorization: Bearer
Query Parameters:
category (optional): Filter by category
tag (optional): Filter by tag
search (optional): Search by name
Response (200 OK):
{
"success": true,
"templates": [
{
"id": "template-uuid-1",
"name": "Sales Report Template",
"description": "Quarterly sales report",
"fileName": "sales-report-template.docx",
"category": "reports",
"tags": ["sales", "quarterly", "report"],
"fileSize": 45678,
"uploadedAt": "2026-02-12T10:30:00Z",
"lastUsedAt": "2026-02-12T11:00:00Z"
},
{
"id": "template-uuid-2",
"name": "Invoice Template",
"description": "Standard invoice format",
"fileName": "invoice-template.docx",
"category": "invoices",
"tags": ["invoice", "billing"],
"fileSize": 32000,
"uploadedAt": "2026-01-15T09:00:00Z",
"lastUsedAt": "2026-02-10T14:30:00Z"
}
],
"totalCount": 2
}
---
Get detailed information about a specific template.
Endpoint: GET /:templateId
Headers:
Authorization: Bearer
Path Parameters:
templateId: Template UUID
Response (200 OK):
{
"success": true,
"template": {
"id": "template-uuid",
"name": "Sales Report Template",
"description": "Quarterly sales report",
"fileName": "sales-report-template.docx",
"category": "reports",
"tags": ["sales", "quarterly", "report"],
"fileSize": 45678,
"filePath": "/templates/user-uuid/sales-report-template.docx",
"uploadedAt": "2026-02-12T10:30:00Z",
"lastUsedAt": "2026-02-12T11:00:00Z",
"usageCount": 15
}
}
---
Download template .docx file.
Endpoint: GET /:templateId/download
Headers:
Authorization: Bearer
Response (200 OK):
application/vnd.openxmlformats-officedocument.wordprocessingml.document
attachment; filename="sales-report-template.docx"
Usage:
const response = await fetch(https://app.datapublisher.io/api/word-templates/${templateId}/download, {
headers: { 'Authorization': Bearer ${jwtToken} }
});
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'template.docx';
a.click();
---
Extract OOXML content for Office.js insertion.
Endpoint: GET /:templateId/ooxml
Headers:
Authorization: Bearer
Response (200 OK):
{
"success": true,
"templateId": "template-uuid",
"ooxml": "... ",
"sections": [
{
"type": "header",
"ooxml": "... "
},
{
"type": "body",
"ooxml": "... "
},
{
"type": "footer",
"ooxml": "... "
}
]
}
Usage with Office.js:
// Insert template OOXML into current document
const response = await fetch(https://app.datapublisher.io/api/word-templates/${templateId}/ooxml, {
headers: { 'Authorization': Bearer ${jwtToken} }
});
const { ooxml } = await response.json();
await Word.run(async (context) => {
const body = context.document.body;
body.insertOoxml(ooxml, Word.InsertLocation.replace);
await context.sync();
});
---
Remove a template from the library.
Endpoint: DELETE /:templateId
Headers:
Authorization: Bearer
Response (200 OK):
{
"success": true,
"message": "Template deleted successfully"
}
---
Save the current Word document as a reusable template.
Endpoint: POST /from-document
Headers:
Authorization: Bearer
Content-Type: application/json
Request Body:
{
"name": "My Custom Template",
"description": "Created from current document",
"category": "custom",
"tags": ["custom", "letter"],
"documentOoxml": "... "
}
Response (200 OK):
{
"success": true,
"template": {
"id": "template-uuid",
"name": "My Custom Template",
"fileName": "my-custom-template.docx",
"fileSize": 38000,
"createdAt": "2026-02-12T11:00:00Z"
},
"message": "Template saved successfully"
}
Office.js Implementation:
// Get current document OOXML
await Word.run(async (context) => {
const body = context.document.body;
const ooxml = body.getOoxml();
await context.sync();
// Save as template
const response = await fetch('https://app.datapublisher.io/api/word-templates/from-document', {
method: 'POST',
headers: {
'Authorization': Bearer ${jwtToken},
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'My Template',
description: 'From current doc',
documentOoxml: ooxml.value
})
});
});
---
Pre-defined categories:
reports - Business reports
letters - Letters and correspondence
invoices - Invoices and billing
proposals - Business proposals
contracts - Legal contracts
forms - Forms and applications
custom - User-defined templates
---
---
---
| Status Code | Description |
|-------------|-------------|
| 400 | Invalid file format or missing fields |
| 401 | Unauthorized - invalid JWT |
| 404 | Template not found |
| 413 | File size exceeds 10MB limit |
| 500 | Template processing failed |
---
// Upload template
async function uploadTemplate(file, name) {
const formData = new FormData();
formData.append('template', file);
formData.append('name', name);
formData.append('category', 'reports');
const response = await fetch('https://app.datapublisher.io/api/word-templates/upload', {
method: 'POST',
headers: { 'Authorization': Bearer ${jwtToken} },
body: formData
});
return await response.json();
}
// List templates
async function listTemplates() {
const response = await fetch('https://app.datapublisher.io/api/word-templates', {
headers: { 'Authorization': Bearer ${jwtToken} }
});
const { templates } = await response.json();
return templates;
}
// Load template into document
async function loadTemplate(templateId) {
// Get OOXML
const response = await fetch(https://app.datapublisher.io/api/word-templates/${templateId}/ooxml, {
headers: { 'Authorization': Bearer ${jwtToken} }
});
const { ooxml } = await response.json();
// Insert into Word
await Word.run(async (context) => {
const body = context.document.body;
body.insertOoxml(ooxml, Word.InsertLocation.replace);
await context.sync();
});
}
// Save current document as template
async function saveAsTemplate(name, description) {
const ooxml = await Word.run(async (context) => {
const body = context.document.body;
const ooxmlObj = body.getOoxml();
await context.sync();
return ooxmlObj.value;
});
const response = await fetch('https://app.datapublisher.io/api/word-templates/from-document', {
method: 'POST',
headers: {
'Authorization': Bearer ${jwtToken},
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: name,
description: description,
documentOoxml: ooxml
})
});
return await response.json();
}
---
{{CustomerName}}) for merge fields
---