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
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Unique template name |
subject | string | No | Subject line with variables |
body | string | Yes | HTML body with Handlebars variables |
description | string | No | Internal 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
| Field | Type | Required | Description |
|---|---|---|---|
to | string | Yes | Recipient email address |
variables | object | Yes | Template variables |
from | string | No | Sender address |
replyTo | string | No | Reply-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
| Method | Scope |
|---|---|
px.listTemplates() | templates:read |
px.createTemplate() | templates:write |
px.renderTemplate() | templates:read |
px.sendTemplate() | templates:read + messaging:send |