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:read

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>"
  }
}

Missing variables

If a variable is referenced in the template but not provided in the request, it renders as an empty string. 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:read scope