PlatformXeDocs
Get API Key

Manage Templates

Create, list, update, and delete message templates.

Manage reusable message templates via the API.

Scope: templates:write (create/update/delete), templates:read (list/get)

Rate limit: 1,000/hr

Create a template

POST /api/v1/templates

FieldTypeRequiredDescription
namestringYesUnique template name (used as a slug)
subjectstringNoSubject line template (supports variables)
bodystringYesHTML body with Handlebars variables
descriptionstringNoInternal description
curl -X POST https://api.platformxe.com/api/v1/templates \
  -H "Content-Type: application/json" \
  -H "x-api-key: pxk_live_your_api_key_here" \
  -d '{
    "name": "welcome-email",
    "subject": "Welcome to {{appName}}, {{firstName}}!",
    "body": "<h1>Welcome, {{firstName}}!</h1><p>Get started with {{appName}}.</p>",
    "description": "Sent after user registration"
  }'
await px.createTemplate({
  name: 'welcome-email',
  subject: 'Welcome to {{appName}}, {{firstName}}!',
  body: '<h1>Welcome, {{firstName}}!</h1><p>Get started with {{appName}}.</p>',
  description: 'Sent after user registration',
});

List templates

GET /api/v1/templates

curl https://api.platformxe.com/api/v1/templates \
  -H "x-api-key: pxk_live_your_api_key_here"
const templates = await px.listTemplates();

Get a template

GET /api/v1/templates/:id

curl https://api.platformxe.com/api/v1/templates/tpl_abc123 \
  -H "x-api-key: pxk_live_your_api_key_here"

Update a template

PATCH /api/v1/templates/:id

Send only the fields to change. Every field is optional.

FieldTypeDescription
namestringTemplate name (non-empty)
descriptionstringInternal description
subjectstringSubject line template
bodyBlocksTemplateBlock[]Replaces the body. Each block has a type of text, heading, button, image, divider or spacer, plus content / level / label / url / src / alt / height as the type needs.
variablesstring[]Declared variable names
ctaLabelstring | nullCall-to-action button label. null clears it.
ctaUrlstring | nullCall-to-action URL — http(s) only. null clears it.

Unknown fields are ignored. A malformed bodyBlocks entry (for example an unknown type) returns VALIDATION_ERROR (HTTP 400).

Clearing a field

description, ctaLabel and ctaUrl are nullable, so sending null clears them. Omitting a field leaves it unchanged, and sending null for a non-nullable field (name, subject) is rejected with VALIDATION_ERROR.

curl -X PATCH https://api.platformxe.com/api/v1/templates/tpl_abc123 \
  -H "Content-Type: application/json" \
  -H "x-api-key: pxk_live_your_api_key_here" \
  -d '{ "ctaLabel": null, "ctaUrl": null }'

ctaUrl must be an absolute http:// or https:// URL, on create and on update. javascript: and data: URLs are rejected with VALIDATION_ERROR (HTTP 400) — a CTA is rendered into email and chat surfaces.

curl -X PATCH https://api.platformxe.com/api/v1/templates/tpl_abc123 \
  -H "Content-Type: application/json" \
  -H "x-api-key: pxk_live_your_api_key_here" \
  -d '{
    "bodyBlocks": [
      { "type": "heading", "content": "Welcome aboard, {{firstName}}!", "level": 1 },
      { "type": "text", "content": "Your account is ready." }
    ],
    "ctaLabel": "Open dashboard",
    "ctaUrl": "https://app.example.com"
  }'

Delete a template

DELETE /api/v1/templates/:id

curl -X DELETE https://api.platformxe.com/api/v1/templates/tpl_abc123 \
  -H "x-api-key: pxk_live_your_api_key_here"

Deleting a template is permanent. Any code referencing the template ID will receive a NOT_FOUND error. Consider disabling templates instead by adding a deprecated flag in the description.

Error responses

CodeDescription
BAD_REQUESTMissing template name or body
CONFLICTTemplate with that name already exists
FORBIDDENAPI key missing required scope
NOT_FOUNDTemplate does not exist