Word template filler API
Fill a Word .docx template with {placeholders}, table-row loops and conditions from JSON; merge many rows into a zip of documents. Formats VND and dates.
Upload a Word document containing tags and send the data as JSON: {ho_ten} inserts a value (dotted paths such as {ben_a.ten} work), {#items}…{/items} repeats content for each element of an array, {#co_bao_hiem}…{/co_bao_hiem} shows a block only when the value is true and {^co_bao_hiem}…{/co_bao_hiem} when it is false or empty. A loop whose tags sit in a table row repeats the row (invoice and contract lines), one across paragraphs repeats the paragraphs, one inside a paragraph repeats the text in place. {$index} numbers the rows.
Filters format values the Vietnamese way: {luong|money} gives 15.500.000, {luong|words} "Mười lăm triệu năm trăm nghìn đồng", {ngay|date} 11/11/2026, {ngay|date_vi} "ngày 11 tháng 11 năm 2026", plus upper, lower, trim and default:…. Tags that Word split into several runs while you typed (spell check, formatting changes) are merged first, so they work as typed; formatting of the first character of the tag is kept. Headers, footers and footnotes are filled too; {{name}} delimiters are detected automatically.
Send rows (an array) instead of data to merge many documents at once: you get a zip, file names from filename such as HD_{so_hd}. action=tags lists the tags of a template. The output is .docx (no PDF conversion); files are processed in memory and not stored.
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
template | body | file | yes | The .docx template (multipart template or file, or template_base64). | |
data | body | object | no | Values for one document (JSON object). | |
rows | body | array | no | Batch merge: an array of objects, returns a zip (max 500). | |
filename | body | string | no | document | Output name, with tags: HD_{so_hd}. |
output | body|query | string | no | docx | docx (file) or json (text preview, tags, missing fields, base64). |
action | body|query | string | no | tags: list the tags of the template only. | |
delimiters | body|query | string | no | single { } or double {{ }} (auto-detected). |
Example
curl -X POST "https://apibox.io.vn/v1/docx-template" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "0=@./my-file"const form = new FormData();
form.append('0', fileInput.files[0]);
const res = await fetch('https://apibox.io.vn/v1/docx-template', {
method: 'POST',
headers: { Authorization: 'Bearer YOUR_API_KEY' },
body: form,
});
console.log(await res.json());import requests
res = requests.post(
"https://apibox.io.vn/v1/docx-template",
headers={"Authorization": "Bearer YOUR_API_KEY"},
files={"0": open("my-file", "rb")},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/docx-template');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY'],
CURLOPT_POSTFIELDS => ['0' => new CURLFile('my-file')],
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Response
{
"filename": "document.docx",
"delimiters": "{ }",
"tags": [
{
"name": "so_hd",
"kind": "variable"
},
{
"name": "ho_ten",
"kind": "variable",
"filters": [
"upper"
]
},
{
"name": "luong",
"kind": "variable",
"filters": [
"money"
]
},
{
"name": "luong",
"kind": "variable",
"filters": [
"words"
]
},
{
"name": "items",
"kind": "section"
},
{
"name": "$index",
"kind": "variable"
},
{
"name": "ten",
"kind": "variable"
},
{
"name": "tien",
"kind": "variable",
"filters": [
"money"
]
}
],
"missing_fields": [],
"text": "HỢP ĐỒNG LAO ĐỘNG số 12/2026/HĐLĐ\nBên B: Ông/Bà NGUYỄN VĂN AN, lương 15.500.000 đồng (Mười lăm triệu năm trăm nghìn đồng)\nSTT\nNội dung\nSố tiền\n1\nLương cơ bản\n12.000.000",
"docx_base64": "UEsDBBQAAAgIAAAAAACY9I3b6wAAAM4BAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbH2R…",
"bytes": 1190
}
Use cases
- Generate labour or sales contracts from HR / CRM data
- Mail-merge certificates, invitations or notices into a zip
- Produce quotations and handover minutes with item tables
- Fill official Vietnamese forms kept as Word templates
FAQ
My tag is not replaced: why?
Check action=tags: the tag must use straight braces {…} and no line break inside. Split runs are handled automatically; a missing value is reported in missing_fields (or the x-missing-fields header).
How do I repeat a table row?
Put {#items} in the first cell and {/items} in the last cell of the row (or of a later row): the row(s) are copied for each item, with {$index} as the line number.
Can it output PDF?
No, the result is a .docx. Convert it with Word / LibreOffice, or use /v1/md-pdf for documents written in Markdown.
Related APIs
Image Metadata & EXIF
Read image dimensions, format, EXIF camera data, capture settings and GPS location from JPEG, PNG, WebP, HEIC, AVIF, GIF and more – upload or URL.
PDFPDF Metadata
Read PDF metadata: page count, title, author, creator, producer, dates, PDF version, encryption, form fields and the size of each page (A4, Letter…).
PDF₫Quote & Receipt PDF
Generate clean PDF quotations, receipts, orders and simple invoices from JSON, with Vietnamese text, VAT, totals in words and a VietQR code for payment.