# POST /document-templates/:template_id/render

**Resource:** [Document Templates](./document-templates.md)  
**MCP tool:** `render_document_template`  
**Scopes:** `documents:write`  
**Write operation:** yes

Render a document template to PDF and save to the file library (costs credits). Pass deal_id to auto-fill {{tokens}} from that opportunity. Set preview:true for a FREE dry-run that returns the rendered HTML + any unresolved_tokens WITHOUT saving or charging — use it to validate merge fields before send_for_signing (which resolves strictly and blocks on any gap).

## Parameters

| Name | In | Type | Required | Description |
|------|----|------|----------|-------------|
| `template_id` | path | string | yes |  |
| `deal_id` | body | string | no | Opportunity to resolve merge tokens from. |
| `preview` | body | boolean | no | true = free dry-run: return html + unresolved_tokens + would_send, no PDF saved, no credits charged. |
| `variables` | body | object | no | Extra {{token}} values merged on top of the opportunity data. |
| `strict_tokens` | body | boolean | no | true = fail if any token is unresolved (ignored when preview:true). |
| `folder` | body | string | no |  |
| `filename` | body | string | no |  |
| `document_type` | body | string | no |  |
| `data` | body | object | no |  |

## Request example

```bash
curl -X POST   "https://api.trustpager.com/functions/v1/api/v1/document-templates/:template_id/render"   -H "Authorization: Bearer YOUR_API_KEY"   -H "Content-Type: application/json"   -d '{"data":"..."}'
```

---
Base URL: `https://api.trustpager.com/functions/v1/api/v1` — Auth: `Authorization: Bearer YOUR_API_KEY`