PlatformXeDocs
Get API Key

Templates

SDK methods for managing and rendering message templates.

The SDK provides methods for creating, listing, rendering, and sending message templates.

List templates

const result = await px.listTemplates();

for (const tpl of result.data.templates) {
  console.log(`${tpl.id}: ${tpl.name}`);
}

Create a template

const result = await px.createTemplate({
  name: 'order-confirmation',
  subject: 'Order {{orderId}} Confirmed',
  body: '<h1>Hi {{firstName}}</h1><p>Your order #{{orderId}} has been confirmed.</p>',
  description: 'Sent after order placement',
});

console.log(result.data.id); // "tpl_abc123"

Parameters

FieldTypeRequiredDescription
namestringYesUnique template name
subjectstringNoSubject line with variables
bodystringYesHTML body with Handlebars variables
descriptionstringNoInternal description

Render a template

Render a template with variables without sending it. Useful for previews.

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

console.log(result.data.subject); // "Order ORD-12345 Confirmed" (plain text: variable values are not HTML-escaped; escape it before writing it into HTML)
console.log(result.data.html);    // rendered HTML

Send a template

Render and send in a single call.

const result = await px.sendTemplate('tpl_abc123', {
  to: ['ada@example.com'],
  variables: {
    firstName: 'Ada',
    orderId: 'ORD-12345',
  },
});

console.log(result.data.send.messageId); // "msg_xyz789" (absent when queued)

Parameters

FieldTypeRequiredDescription
tostring[]YesRecipient email addresses
variablesRecord<string, string>NoTemplate variables (default {})
fromstringNoSender address, at most 320 characters (longer: 400 VALIDATION_ERROR)

The endpoint takes no replyTo (it is ignored). A rendered email every provider refuses fails with 400 BAD_REQUEST and is not queued; see Render & Send.

Update a template

await px.updateTemplate('tpl_abc123', {
  body: '<h1>Welcome, {{firstName}}!</h1><p>Your order is ready.</p>',
});

Delete a template

await px.deleteTemplate('tpl_abc123');

Template names must be unique within a tenant. Use descriptive slugs like order-confirmation, password-reset, or welcome-email.

Scopes required

MethodScope
px.listTemplates()templates:read
px.createTemplate()templates:write
px.renderTemplate()templates:write
px.sendTemplate()messaging:send