PlatformXeDocs
Get API Key

Render Template

Render a template with variables and get HTML output.

Render a stored template by passing a variables object. Returns the final HTML without sending it.

Endpoint

POST /api/v1/templates/:id/render

Scope: templates:write

Rate limit: 1,000/hr

Request body

FieldTypeRequiredDescription
variablesobjectYesKey-value pairs to substitute into the template

curl

curl -X POST https://api.platformxe.com/api/v1/templates/tpl_abc123/render \
  -H "Content-Type: application/json" \
  -H "x-api-key: pxk_live_your_api_key_here" \
  -d '{
    "variables": {
      "firstName": "Ada",
      "appName": "Lettings",
      "orderId": "ORD-12345"
    }
  }'

SDK

const result = await px.renderTemplate('tpl_abc123', {
  variables: {
    firstName: 'Ada',
    appName: 'Lettings',
    orderId: 'ORD-12345',
  },
});

console.log(result.data.subject);
// "Welcome to Lettings, Ada!"

console.log(result.data.html);
// "<h1>Welcome, Ada!</h1><p>Get started with Lettings.</p>"

Response

{
  "success": true,
  "data": {
    "subject": "Welcome to Lettings, Ada!",
    "html": "<h1>Welcome, Ada!</h1><p>Get started with Lettings.</p>"
  }
}

How values are inserted

In the HTML body, every value is HTML-escaped (O'Brien & Co becomes O&#39;Brien &amp; Co). The subject and the plain-text part are plain text: values are inserted as written, and a line break in a subject value becomes a space.

Missing variables

If a variable is referenced in the template but not provided in the request, its placeholder is left as written ({{name}}). No error is thrown.

Use the render endpoint during development to preview templates before sending. This lets you iterate on template design without generating actual email sends.

Error responses

CodeDescription
NOT_FOUNDTemplate ID does not exist
BAD_REQUESTVariables is not a valid object
FORBIDDENAPI key missing templates:write scope