Docs
API · templates

Preview a template

Render an unsaved draft — the template fields travel in the request body, so nothing is stored. This is the endpoint behind the dashboard's live template editor.

POST/v1/templates/preview

To render a template you've already saved, use POST /v1/templates/{id}/render instead, which references it by id.

01 Body parameters

All fields are optional — send the draft fields you want to render.

subjectstringOptional
Draft subject line with merge variables.
htmlstringOptional
Draft HTML body.
textstringOptional
Draft plain-text body.
dataobjectOptional
Merge variables to substitute. HTML values are escaped before insertion into the html field.

02 Request

curl https://api.drin.run/v1/templates/preview \
  -H "Authorization: Bearer $DRIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "subject": "Hi {{name}}",
    "html": "<b>Welcome, {{name}}!</b>",
    "data": { "name": "Sam" }
  }'

03 Response

subjectstringOptional
The rendered subject.
htmlstring | nullOptional
The rendered HTML, or null when not supplied or on a syntax error.
textstring | nullOptional
The rendered text, or null.
missingstring[]Optional
Referenced variables absent from data.
errorstringOptional
Present only when a draft field has a template syntax error. The request still returns 200 OK so the editor can show the message inline.
200 OK
{
  "subject": "Hi Sam",
  "html": "<b>Welcome, Sam!</b>",
  "text": null,
  "missing": []
}

04 Syntax error

A malformed block (e.g. an unclosed {{#if}}) returns 200 with an error string rather than a 4xx, so a live editor can surface it without treating it as a failed request.

200 OK · with error
{
  "subject": "Hi Sam",
  "html": null,
  "text": null,
  "missing": [],
  "error": "unexpected end of input in {{#if"
}
HTML escapingValues in data are HTML-escaped before substitution into html. Use the triple-brace {{{raw}}} form only for values you trust to be safe markup.