Generate Document

The generate document endpoint allows you to create a document by filling a template with your data.

Request

POST /v1/templates/{template_id}/generate

Path Parameters

ParameterTypeDescription
template_idstringThe unique identifier of the template to use

Request Body

{
  "data": object,
  "output": {
    "format": "docx" | "pdf"
  }
}

Request Fields

FieldTypeDescription
dataobjectKey-value pairs where keys match template placeholders
outputobjectOptional. Output options
output.formatstringOptional. The desired output format: "docx" (default) or "pdf"

Response

A successful request returns the generated document with the appropriate Content-Type header:

  • application/vnd.openxmlformats-officedocument.wordprocessingml.document for DOCX
  • application/pdf for PDF

Examples

const apiKey = "Your_API_Key";
const templateId = "template_123";

const response = await fetch(`https://templatedocs.io/api/v1/templates/${templateId}/generate`, {
    method: 'POST',
    headers: {
        "Authorization": `Bearer ${apiKey}`,
        "Content-Type": "application/json"
    },
    body: JSON.stringify({
	    data: {
	        firstName: "John",
	        lastName: "Doe",
	        company: "ACME Inc."
	    },
	    output: {
	        format: "pdf"
	    }
	})
});

const blob = await response.blob();