N8N Integration Guide
n8n Integration Guide
Automate document generation, traceability, printing, and more using the DataMagik n8n community node.
Table of Contents
- Overview
- Installation
- Authentication Setup
- Available Resources
- Document Generation
- Traceability & Serial Numbers
- Lookup Tables
- Printer Integration
- Label Processing
- Workflow Examples
- Best Practices
1. Overview
The DataMagik n8n community node (n8n-nodes-datamagik) provides complete integration with the DataMagik API. Build automation workflows combining:
- Document Generation — Create PDFs with automatic completion waiting
- Traceability — Generate and track serial numbers
- Lookup Tables — Access key-value data stores
- Printing — Send jobs to industrial printers
- Labels — Process ZPL templates and generate previews
2. Installation
Option 1: Install via n8n UI (Recommended)
- Go to Settings → Community Nodes
- Enter
n8n-nodes-datamagik - Click Install
- Restart n8n
Option 2: Manual Installation
npm install n8n-nodes-datamagikOption 3: Docker
environment:
- N8N_CUSTOM_EXTENSIONS=n8n-nodes-datamagik3. Authentication Setup
- In n8n, go to Credentials
- Click Add Credential
- Search for DataMagik API
- Enter your API Token (JWT Bearer token from Settings → API Keys in DataMagik)
- Click Save
Authentication Methods:
| Method | Header |
|---|---|
| Bearer Token (Recommended) | Authorization: Bearer your_jwt_token |
| API Key | X-API-Key: your_api_key |
4. Available Resources
| Resource | Description |
|---|---|
| Document | Generate PDFs and HTML documents from templates |
| Traceability | Manage serial number series and generate serials |
| Lookup Table | Access and manage key-value lookup tables |
| Printer | Send print jobs to registered printers |
| Label | Process ZPL templates and generate previews |
5. Document Generation
List Templates
Operation: List Templates — Retrieves all available document templates.
Generate Document
Operation: Generate Document — Creates a document from a template with data substitution.
| Parameter | Description | Required |
|---|---|---|
| Template ID | Template identifier (as string) | Yes |
| Format | pdf or html | Yes |
| Return Type | url (download link) or binary (file data) | Yes |
| Template Data | JSON object with data for the template | Yes |
| Priority | urgent, high, normal, low | No |
| Custom Filename | Override the default filename | No |
Example Template Data:
{
"customer_name": "Acme Corporation",
"invoice_number": "INV-2025-001",
"amount": 1500.00,
"items": [
{ "description": "Widget A", "quantity": 10, "price": 100.00 }
]
}Automatic Completion: When using URL return type, the node automatically polls every 5 seconds for up to 2 minutes until the document is ready.
Important: Always provide template IDs as strings to avoid JavaScript number precision issues. Use {{ String($json.template_id) }} in expressions.
6. Traceability & Serial Numbers
List Series
Operation: List Series — Gets all configured serial number series.
Generate Serial
Operation: Generate Serial
| Parameter | Description | Required |
|---|---|---|
| Series Name | Name of the series | Yes |
| Work Order | Associated work order | No |
| Part Number | Associated part number | No |
| Context Data | Additional metadata (JSON) | No |
Batch Generate Serials
Operation: Batch Generate Serials
| Parameter | Description | Required |
|---|---|---|
| Series Name | Name of the series | Yes |
| Quantity | Number of serials to generate | Yes |
| Work Order | Associated work order | No |
Search Records
Operation: Search Records — Query traceability history by series, work order, date range, or status.
7. Lookup Tables
Lookup Value
Operation: Lookup
| Parameter | Description | Required |
|---|---|---|
| Table Name | Name of the lookup table | Yes |
| Key | Key to look up | Yes |
Bulk Create Data
Operation: Bulk Create Data — Import multiple key-value pairs.
[
{ "key": "PART-001", "value": { "description": "Widget", "price": 25.00 } },
{ "key": "PART-002", "value": { "description": "Gadget", "price": 50.00 } }
]8. Printer Integration
List Printers
Operation: List Printers — Gets all registered printers.
Send Print Job
Operation: Send Print Job
| Parameter | Description | Required |
|---|---|---|
| Printer Name | Name of the registered printer | Yes |
| Format | zpl, pdf, or raw | Yes |
| Data | Content to print | Yes |
| Copies | Number of copies | No |
9. Label Processing
Process Template
Operation: Process Template — Processes a ZPL template with data substitution.
| Parameter | Description | Required |
|---|---|---|
| Template Name | Name of the ZPL template | Yes |
| Data | JSON data for substitution | Yes |
Preview ZPL
Operation: Preview ZPL — Generates a PNG preview image of ZPL label code.
| Parameter | Description | Required |
|---|---|---|
| ZPL Code | Raw ZPL code | Yes |
| Width | Label width in dots | No |
| Height | Label height in dots | No |
| DPI | Printer DPI (203 or 300) | No |
10. Workflow Examples
Invoice Generation from Webhook
[Webhook] → [DataMagik: Generate Document] → [Send Email]- Webhook receives order data
- DataMagik generates invoice PDF
- Send Email attaches the PDF and sends
Serial Number Labels for Production
[Schedule] → [DataMagik: Batch Generate] → [DataMagik: Process Template] → [DataMagik: Print]- Schedule triggers at shift start
- Batch Generate creates 50 serials for the work order
- Process Template generates ZPL for each serial
- Print sends labels to the production printer
Document with Lookup Data
[Trigger] → [DataMagik: Lookup] → [DataMagik: Generate Document]- Trigger receives customer ID
- Lookup fetches customer details
- Generate Document creates invoice with complete data
Complete Manufacturing Flow
[Webhook: Work Order]
→ [DataMagik: Batch Generate Serials]
→ [Loop: For Each Serial]
→ [DataMagik: Process Template]
→ [DataMagik: Send Print Job]
→ [DataMagik: Generate Document (Certificate)]11. Best Practices
Template IDs
- Always use strings for template IDs
- Use
String()wrapper when getting from expressions - Test with actual IDs before production
Error Handling
- Enable Continue on Fail for graceful error handling
- Check the
successfield in all responses - Implement retry logic for transient failures
Performance
- Use URL return type for production workflows
- Batch operations when possible
- Monitor queue priorities for time-sensitive documents
Security
- Store API tokens using n8n credentials (never hardcode)
- Use HTTPS endpoints only
- Rotate tokens periodically
Troubleshooting
| Issue | Solution |
|---|---|
| Authentication failed | Verify API token is correct and not expired |
| Template not found | Check template ID is a string, verify permissions |
| Access denied | Ensure API key has required permissions |
| Timeout | Increase polling timeout or check API health |
| Invalid JSON | Validate template data is proper JSON format |
Required Permissions
Your API key user needs one of these permissions:
DataMagik - UserDataMagik - BuilderDataMagik - Viewer
HTTP Request Alternative
If you prefer using the built-in HTTP Request node:
URL: https://data-magik.com/api/document-designer/generate
Method: POST
Headers: { "Authorization": "Bearer your_jwt_token", "Content-Type": "application/json" }
Body: {
"template_id": "1097823044285431810",
"format": "pdf",
"return_type": "url",
"data": { "customer_name": "{{ $json.customer_name }}" }
}Note: When using HTTP Request, you must manually implement polling for document completion.