Skip to content

Templates

Templates let you define reusable email layouts with placeholder variables. Store your HTML once, then send personalized emails by passing different data each time.

POST /api/v1/templates

Terminal window
curl -X POST https://relaypost.dev/api/v1/templates \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"name": "Order Confirmation",
"subject": "Your order #{{orderNumber}}",
"html": "<h1>Thanks, {{customerName}}!</h1><p>Your order #{{orderNumber}} totaling {{total}} has been confirmed.</p>",
"text": "Thanks, {{customerName}}! Your order #{{orderNumber}} totaling {{total}} has been confirmed."
}'
FieldTypeRequiredDescription
namestringYesTemplate name
subjectstringYesSubject line (supports {{variables}})
htmlstringNoHTML body (supports {{variables}})
textstringNoPlain text body (supports {{variables}})
{
"data": {
"id": "tmpl_abc123",
"name": "Order Confirmation",
"subject": "Your order #{{orderNumber}}",
"html_body": "<h1>Thanks, {{customerName}}!</h1><p>Your order #{{orderNumber}} totaling {{total}} has been confirmed.</p>",
"text_body": "Thanks, {{customerName}}! Your order #{{orderNumber}} totaling {{total}} has been confirmed.",
"variables": null,
"is_active": true,
"created_at": "2025-01-15T10:30:00.000Z",
"updated_at": "2025-01-15T10:30:00.000Z"
}
}

Reference the template by ID and pass the variable values using POST /api/v1/emails/send:

Terminal window
curl -X POST https://relaypost.dev/api/v1/emails/send \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"from": { "email": "orders@yourapp.com" },
"to": [{ "email": "customer@example.com" }],
"subject": "Your order #1234",
"template_id": "tmpl_abc123",
"template_data": {
"customerName": "Jane",
"orderNumber": "1234",
"total": "$49.99"
}
}'

GET /api/v1/templates

Terminal window
curl "https://relaypost.dev/api/v1/templates?page=1&limit=20" \
-H "Authorization: Bearer YOUR_API_KEY"
ParameterTypeDefaultDescription
pageinteger1Page number
limitinteger20Results per page (max 100)
{
"data": [
{
"id": "tmpl_abc123",
"name": "Order Confirmation",
"subject": "Your order #{{orderNumber}}",
"html_body": "...",
"text_body": "...",
"variables": null,
"is_active": true,
"created_at": "2025-01-15T10:30:00.000Z",
"updated_at": "2025-01-15T10:30:00.000Z"
}
],
"pagination": {
"page": 1,
"limit": 20,
"total_count": 5,
"total_pages": 1
}
}

PUT /api/v1/templates/:id

Only include the fields you want to change — everything else stays the same.

Terminal window
curl -X PUT https://relaypost.dev/api/v1/templates/tmpl_abc123 \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"html": "<h1>Updated layout</h1><p>Hello {{customerName}}</p>"
}'
FieldTypeRequiredDescription
namestringNoUpdated template name
subjectstringNoUpdated subject line
htmlstringNoUpdated HTML body
textstringNoUpdated plain text body

At least one field must be provided.

{
"data": {
"id": "tmpl_abc123",
"name": "Order Confirmation",
"subject": "Your order #{{orderNumber}}",
"html_body": "<h1>Updated layout</h1><p>Hello {{customerName}}</p>",
"text_body": "Thanks, {{customerName}}! Your order #{{orderNumber}} totaling {{total}} has been confirmed.",
"variables": null,
"is_active": true,
"created_at": "2025-01-15T10:30:00.000Z",
"updated_at": "2025-01-15T11:00:00.000Z"
}
}
StatusCodeDescription
400VALIDATION_ERRORNo update fields provided or invalid values
404NOT_FOUNDTemplate not found or belongs to another organization

DELETE /api/v1/templates/:id

Terminal window
curl -X DELETE https://relaypost.dev/api/v1/templates/tmpl_abc123 \
-H "Authorization: Bearer YOUR_API_KEY"
{
"data": {
"id": "tmpl_abc123",
"deleted": true
}
}
StatusCodeDescription
404NOT_FOUNDTemplate not found or belongs to another organization