Rendering
Endpoints for rendering templates to generate output documents in various formats.
Rendering Overview
Templates can be rendered to multiple output formats:
- pdf - PDF documents
- html - HTML output
- docx - Microsoft Word documents
- xlsx - Microsoft Excel spreadsheets
- text - Plain text
Rendering process:
- Resolve input parameters (from request or defaults)
- Execute processors to fetch data
- Build template context with data
- Execute template engine (Nunjucks, Handlebars, etc.)
- Apply output handler to generate final format
GET /api/templates/{id}/_render
Render a template using GET parameters.
Authentication: Required (session)
Pre-blocks: template.lookup(params.id), template.retrievePayload, template.resolveParams, template.processInputs, template.context, template.handler
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
output | string | Output format (pdf, html, docx, xlsx, text) - overrides template default |
progress | string | Progress tracking ID for long-running renders |
download | boolean | Force download with Content-Disposition header |
filename | string | Custom filename for download |
payloadId | string | ID of stored payload from previous render |
params | object | Input parameter values as JSON object |
Additional parameters specific to inputs can be passed as query parameters.
Example Request:
GET /api/templates/abc123/_render?output=pdf&download=true&filename=report.pdf¶ms[report_title]=Q1%20Sales¶ms[start_date]=2024-01-01
Response:
Returns the rendered document with appropriate Content-Type header:
application/pdffor PDFtext/htmlfor HTMLapplication/vnd.openxmlformats-officedocument.wordprocessingml.documentfor DOCX- etc.
If download=true, includes Content-Disposition: attachment; filename="..." header.
POST /api/templates/{id}/_render
Render a template using POST body for parameters.
Authentication: Required (session)
Pre-blocks: template.lookup(params.id), template.resolveParams, template.processInputs, template.context, template.handler
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
output | string | Output format (can also be in payload) |
progress | string | Progress tracking ID |
download | boolean | Force download (can also be in payload) |
filename | string | Custom filename (can also be in payload) |
params | object | Input parameters (can also be in payload) |
Request Body:
| Field | Type | Description |
|---|---|---|
output | string | Output format override |
progress | string | Progress tracking ID |
download | boolean | Force download |
filename | string | Custom filename |
params | object | Input parameter values |
Additional fields can be included for specific input values.
Example Request:
{
"output": "pdf",
"download": true,
"filename": "quarterly-report.pdf",
"params": {
"report_title": "Q1 Sales Report",
"start_date": "2024-01-01",
"end_date": "2024-03-31",
"region": "north"
}
}
Response:
Returns the rendered document with appropriate content type and headers.
Timeout:
Socket timeout is set to 60 minutes (3,600,000ms) to accommodate long-running renders.
POST /api/templates/{id}/_render-params
Store render parameters for later use (returns a payloadId for subsequent render calls).
Authentication: Required (session)
Pre-blocks: template.lookup(params.id)
Request Body:
Object containing parameter values and render options.
Example Request:
{
"report_title": "Q1 Sales Report",
"start_date": "2024-01-01",
"end_date": "2024-03-31",
"region": "north",
"output": "pdf"
}
Response:
{
"payloadId": "payload-abc123",
"expiresAt": "2024-01-16T10:30:00Z"
}
Use the returned payloadId in subsequent GET /api/templates/{id}/_render?payloadId=... requests.
Rendering Error Handling
If processors encounter errors during rendering (e.g., dataset query fails, data source unavailable), the response depends on whether the template is a draft:
Draft templates: Returns an error page showing all processor errors with details.
Published templates: Returns an HTTP error response.
Example error response for drafts:
<html>
<body>
<h1>Template Rendering Errors</h1>
<ul>
<li>Processor 'sales_data': Dataset not found</li>
<li>Processor 'summary': AI assistant unavailable</li>
</ul>
</body>
</html>
Progress Tracking
For long-running renders, include a progress parameter to track rendering status via server-sent events or polling.
Handler Options
Each output handler supports specific options in handlerOptions:
PDF Handler:
pageSize- Page size (letter, legal, a4, etc.)margin- Margin size (CSS units)orientation- portrait or landscapeheader- Header configurationfooter- Footer configuration
DOCX Handler:
pageSize- Page sizemargin- Margin configurationorientation- portrait or landscape
XLSX Handler:
sheetName- Worksheet nameautoWidth- Auto-size columns