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"
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.messageId); // "msg_xyz789"

Parameters

FieldTypeRequiredDescription
tostringYesRecipient email address
variablesobjectYesTemplate variables
fromstringNoSender address
replyTostringNoReply-to address

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:read
px.sendTemplate()templates:read + messaging:send