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.

POSThttps://apibox.io.vn/v1/docx-template

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

NameInTypeRequiredDefault
templatebodyfileyesThe .docx template (multipart template or file, or template_base64).
databodyobjectnoValues for one document (JSON object).
rowsbodyarraynoBatch merge: an array of objects, returns a zip (max 500).
filenamebodystringnodocumentOutput name, with tags: HD_{so_hd}.
outputbody|querystringnodocxdocx (file) or json (text preview, tags, missing fields, base64).
actionbody|querystringnotags: list the tags of the template only.
delimitersbody|querystringnosingle { } 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"

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

Start with 1,000 free requests every month. Get free API key →