Overview
This node transforms the content of a DOCX file based on a provided JSON template. It fetches a DOCX document from a specified URL, applies data from a JSON structure to fill or modify the document using templating, and outputs the resulting DOCX file. This is useful for automating document generation tasks such as creating personalized reports, contracts, invoices, or letters where the base DOCX template is dynamically populated with data.
Practical examples:
- Generating customized offer letters by filling in candidate details.
- Creating invoices by merging billing data into a DOCX invoice template.
- Producing reports where charts or tables are dynamically inserted based on input data.
Properties
| Name | Meaning |
|---|---|
| File URL | URL path where the source DOCX template file can be retrieved. |
| JSON Template | JSON object representing the data template used to populate the DOCX file's placeholders. |
Output
The node outputs binary data representing the transformed DOCX file. The output structure includes:
json: An empty JSON object (no specific JSON output).binary: Contains the generated DOCX file under a binary property with:data: The binary content of the generated DOCX file.fileName: Set to"test.docx"(default filename).mimeType: Set to"mimeType"(placeholder string; likely should be"application/vnd.openxmlformats-officedocument.wordprocessingml.document").
This binary output can be used downstream in workflows to save the file, send it via email, or upload it elsewhere.
Dependencies
- External libraries:
docx-templates: Used to generate the DOCX report by applying the JSON template to the DOCX file.node-fetch: Used to fetch the DOCX file from the provided URL.
- n8n helpers: Utilizes n8n’s helper method to prepare binary data for output.
- Network access: Requires internet or network access to fetch the DOCX file from the given URL.
Troubleshooting
- Common issues:
- Invalid or unreachable File URL: The node will fail if the URL is incorrect or the file cannot be fetched.
- Malformed JSON Template: If the JSON template is not valid JSON, parsing will fail.
- Template placeholders mismatch: If the JSON template does not match placeholders in the DOCX, the output may be incomplete or incorrect.
- Error messages:
- Errors during fetching the file or parsing JSON will throw exceptions.
- If
continueOnFailis enabled, errors for individual items will be captured in the output with error details.
- Resolutions:
- Verify the File URL is accessible and points to a valid DOCX file.
- Ensure the JSON Template is correctly formatted JSON matching the DOCX template placeholders.
- Check network connectivity and permissions if fetching fails.
Links and References
- docx-templates GitHub repository – Documentation and usage examples for the templating library.
- node-fetch GitHub repository – For understanding how file fetching works.
- n8n documentation – General guidance on working with binary data and custom nodes.