1 creditDOCX Template API — render Word documents from JSON
Upload a .docx with {{ variables }} and table loops; render it from JSON data to DOCX or PDF.
A DOCX template is a normal Word document with {{ }} placeholders and row loops inside its tables. ASHDOCS fills it from a JSON payload and returns the finished document — which means the person who owns the wording can keep owning it, in Word, without touching any code.
How does the DOCX Template API work?
One HTTP request from any language. Every ASHDOCS endpoint uses the same X-API-Key header.
curl -X POST https://www.ashdocs.com/api/v2/tools/docx-template \
-H "X-API-Key: ash_live_..." \
-H "Content-Type: application/json" \
-d '{"template_id":"dtpl_...","data":{"customer_name":"Ada","items":[{"name":"Widget","price":10}]},"output":"pdf"}'import requests
r = requests.post(
"https://www.ashdocs.com/api/v2/tools/docx-template",
headers={"X-API-Key": "ash_live_..."},
json={
"template_id": "dtpl_...",
"data": {
"customer_name": "Ada",
"items": [
{
"name": "Widget",
"price": 10
}
]
},
"output": "pdf"
},
)
job = r.json()
print(job["status"], job.get("url"))const res = await fetch("https://www.ashdocs.com/api/v2/tools/docx-template", {
method: "POST",
headers: { "X-API-Key": "ash_live_...", "Content-Type": "application/json" },
body: JSON.stringify({"template_id":"dtpl_...","data":{"customer_name":"Ada","items":[{"name":"Widget","price":10}]},"output":"pdf"}),
});
const job = await res.json();
console.log(job.status, job.url);using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-Key", "ash_live_...");
var body = new StringContent(
"{\"template_id\":\"dtpl_...\",\"data\":{\"customer_name\":\"Ada\",\"items\":[{\"name\":\"Widget\",\"price\":10}]},\"output\":\"pdf\"}",
Encoding.UTF8, "application/json");
var res = await client.PostAsync("https://www.ashdocs.com/api/v2/tools/docx-template", body);
var job = await res.Content.ReadAsStringAsync();
Console.WriteLine(job);import java.io.ByteArrayOutputStream;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
public class Sample {
public static void main(String[] args) throws Exception {
String json = "{\"template_id\":\"dtpl_...\",\"data\":{\"customer_name\":\"Ada\",\"items\":[{\"name\":\"Widget\",\"price\":10}]},\"output\":\"pdf\"}";
HttpRequest req = HttpRequest.newBuilder(URI.create("https://www.ashdocs.com/api/v2/tools/docx-template"))
.header("X-API-Key", "ash_live_...")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse<String> res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(res.body());
}
}#include <stdio.h>
#include <curl/curl.h>
int main(void) {
CURL *curl = curl_easy_init();
if (!curl) return 1;
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "X-API-Key: ash_live_...");
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"template_id\":\"dtpl_...\",\"data\":{\"customer_name\":\"Ada\",\"items\":[{\"name\":\"Widget\",\"price\":10}]},\"output\":\"pdf\"}");
curl_easy_setopt(curl, CURLOPT_URL, "https://www.ashdocs.com/api/v2/tools/docx-template");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
CURLcode rc = curl_easy_perform(curl);
printf("\n");
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
return rc == CURLE_OK ? 0 : 1;
}Common use cases
- →Generating contracts from CRM data
- →Turning an invoice template into a per-order document
- →Producing personalized letters or certificates in bulk
Frequently asked questions
Do I need Word installed anywhere?+
No. The template is a .docx file; filling it does not require Word, and neither does converting it.
Why did my placeholder not get replaced?+
Almost always because Word split it across text runs. Retype it in one action or paste it as plain text.
Can a template have conditional sections?+
Yes. Templates are filled by docxtpl in a sandboxed Jinja2 environment, so {% if %} … {% endif %} blocks work alongside {{ }} placeholders and {%tr for %} row loops; docxtpl's {%p if %} form shows or hides a whole paragraph.
How much does it cost?+
One credit for a .docx, two when you ask for the PDF — the conversion is the second credit.