Email Templates
Email templates in MessagePipe allow you to create reusable HTML email designs with variable injection for personalized messaging.
Creating Email Templates
Create a new email template by sending HTML content. The subject field is now required at creation time.
POST /templates?projectId={projectId}&name={templateName}&subject={subject}
Content-Type: text/html
Authorization: Bearer {your-jwt-token}
<!DOCTYPE html>
<html>
<head>
<title>Welcome Email</title>
</head>
<body>
<h1>Welcome {{firstName}}!</h1>
<p>Thank you for joining {{companyName}}.</p>
</body>
</html>
Response:
{
"id": "template-uuid",
"name": "welcome-email",
"projectId": "project-uuid",
"createdAt": "2024-01-01T10:00:00Z"
}
Template Variables
Templates support variable injection using double curly braces: {{variableName}}
Retrieving Template Variables
Get all variables used in a template:
GET /templates/variables/{templateId}
Authorization: Bearer {your-jwt-token}
Response:
{
"variables": ["firstName", "companyName", "activationUrl"]
}
Template Preview
Preview how a template looks with actual data:
POST /templates/preview
Content-Type: application/json
x-api-key: {your-api-key}
{
"templateId": "template-uuid",
"projectId": "project-uuid",
"variables": {
"firstName": "John",
"companyName": "Nobu"
}
}
The projectId is required when authenticating with a JWT token instead of an API key.
Response:
{
"preview": "<h1>Welcome John!</h1><p>Thank you for joining Nobu.</p>"
}
Render Template (Simple Testing)
Quickly render a template in the browser for visual testing. This endpoint does not inject variables. It's for basic layout inspection only.
GET /templates/render/{templateId}
Authorization: Bearer {your-jwt-token}
Managing Templates
Get All Templates
Supports optional filtering by project and pagination:
GET /templates?projectId={projectId}&page=1&limit=20
Authorization: Bearer {your-jwt-token}
| Query Param | Required | Description |
|---|---|---|
projectId | No | Filter templates by project |
page | No | Page number for pagination |
limit | No | Items per page (max: 100) |
Get Project Templates
GET /templates/project/{projectId}?page=1&limit=20
Authorization: Bearer {your-jwt-token}
Get Specific Template
GET /templates/{templateId}
Authorization: Bearer {your-jwt-token}
Update Template
The name and subject fields are optional on update. Body content is also optional. Omit any field you don't want to change.
PUT /templates/{templateId}?name=updated-name&subject=Updated+Subject
Content-Type: text/html
x-api-key: {your-api-key}
<html>Updated content here</html>
Delete Template
DELETE /templates/{templateId}
Authorization: Bearer {your-jwt-token}
Import & Export Templates
You can export all templates from a project as a JSON file and import them into another project. This is useful for copying template sets across environments.
Export Templates
GET /templates/export/{projectId}
Authorization: Bearer {your-jwt-token}
Response:
{
"templates": [...],
"exportedAt": "2024-01-01T10:00:00Z",
"projectId": "project-uuid",
"projectName": "My Project",
"totalTemplates": 5
}
Import Templates
Upload the JSON file exported from another project:
POST /templates/import/{projectId}
Content-Type: multipart/form-data
Authorization: Bearer {your-jwt-token}
file: <exported-templates.json>
Best Practices
- Always provide a
subjectwhen creating email templates. It is required - Use semantic variable names that clearly indicate their purpose
- Test templates with preview before sending
- Keep HTML simple and email-client compatible
- Include fallback text for images and complex styling
- Use descriptive template names for easy identification
- Use import/export to replicate template sets across staging and production projects