Email Template API
Create, list, preview, and manage email templates with variable substitution using syntax.
Endpoints
| Method | Path | Description |
|---|---|---|
| GET | /api/email-templates/:orgId/list | List templates (filterable by type) |
| GET | /api/email-templates/:orgId/variables/:type | Get available variables for a template type |
| POST | /api/email-templates/:orgId/create | Create a new template |
| GET | /api/email-templates/:orgId/:templateId | Get template by ID |
| PUT | /api/email-templates/:orgId/:templateId/update | Update a template |
| DELETE | /api/email-templates/:orgId/:templateId/delete | Delete a template |
| POST | /api/email-templates/:orgId/:templateId/preview | Preview rendered template |
| POST | /api/email-templates/:orgId/:templateId/set-default | Set template as default for its type |
Path Parameters
| Parameter | Type | Description |
|---|---|---|
orgId | string | Organization ID |
templateId | string | Email template ID |
type | string | Template type (see below) |
Query Parameters
| Endpoint | Parameter | Type | Description |
|---|---|---|---|
| List | type | string | Filter by template type |
Template Types
| Type | Description |
|---|---|
invoice | Invoice email |
booking_confirmation | Booking confirmation email |
payment_receipt | Payment receipt email |
quote | Quotation email |
welcome_guest | Guest welcome email |
checkout_summary | Check-out summary email |
custom | Custom template |
List Templates
GET /api/email-templates/:orgId/list
GET /api/email-templates/:orgId/list?type=invoiceResponse — 200 OK
json
{
"success": true,
"data": [
{
"_id": "66611b2c3d4e5f6a7b8c9d0e",
"name": "Standard Invoice",
"type": "invoice",
"subject": "Invoice {{invoice_number}} from {{organization_name}}",
"isDefault": true,
"createdAt": "2026-02-20T08:00:00.000Z"
},
{
"_id": "66611b2c3d4e5f6a7b8c9d0f",
"name": "Booking Confirmation",
"type": "booking_confirmation",
"subject": "Booking Confirmed — {{booking_number}}",
"isDefault": true,
"createdAt": "2026-02-20T08:00:00.000Z"
},
{
"_id": "66611b2c3d4e5f6a7b8c9d10",
"name": "Payment Thank You",
"type": "payment_receipt",
"subject": "Payment Receipt — {{payment_number}}",
"isDefault": true,
"createdAt": "2026-02-20T08:00:00.000Z"
}
]
}Get Template Variables
GET /api/email-templates/:orgId/variables/:typeExample: GET /api/email-templates/:orgId/variables/invoice
Response — 200 OK
json
{
"success": true,
"data": {
"type": "invoice",
"variables": [
{ "key": "invoice_number", "description": "Invoice number (e.g. INV-1042)" },
{ "key": "invoice_date", "description": "Invoice date" },
{ "key": "due_date", "description": "Payment due date" },
{ "key": "guest_name", "description": "Guest full name" },
{ "key": "guest_email", "description": "Guest email address" },
{ "key": "room_number", "description": "Room number" },
{ "key": "check_in_date", "description": "Check-in date" },
{ "key": "check_out_date", "description": "Check-out date" },
{ "key": "subtotal", "description": "Subtotal before tax" },
{ "key": "tax_amount", "description": "Total tax amount" },
{ "key": "total_amount", "description": "Grand total" },
{ "key": "organization_name", "description": "Organization name" },
{ "key": "organization_email", "description": "Organization email" },
{ "key": "organization_phone", "description": "Organization phone" },
{ "key": "organization_address", "description": "Organization address" }
]
}
}Create Template
POST /api/email-templates/:orgId/createRequest Body
json
{
"name": "Detailed Invoice",
"type": "invoice",
"subject": "Invoice {{invoice_number}} — {{organization_name}}",
"headerColor": "#1a73e8",
"headerText": "Tax Invoice",
"bodyHtml": "<p>Dear {{guest_name}},</p><p>Please find your invoice <strong>{{invoice_number}}</strong> dated {{invoice_date}} attached.</p><table><tr><td>Room</td><td>{{room_number}}</td></tr><tr><td>Check-in</td><td>{{check_in_date}}</td></tr><tr><td>Check-out</td><td>{{check_out_date}}</td></tr><tr><td>Subtotal</td><td>{{subtotal}}</td></tr><tr><td>Tax</td><td>{{tax_amount}}</td></tr><tr><td><strong>Total</strong></td><td><strong>{{total_amount}}</strong></td></tr></table>",
"footerText": "Thank you for staying with us! — {{organization_name}}"
}Response — 201 Created
json
{
"success": true,
"message": "Email template created successfully",
"data": {
"_id": "66611b2c3d4e5f6a7b8c9d11",
"name": "Detailed Invoice",
"type": "invoice",
"subject": "Invoice {{invoice_number}} — {{organization_name}}",
"headerColor": "#1a73e8",
"headerText": "Tax Invoice",
"bodyHtml": "<p>Dear {{guest_name}},</p><p>Please find your invoice <strong>{{invoice_number}}</strong> dated {{invoice_date}} attached.</p><table><tr><td>Room</td><td>{{room_number}}</td></tr><tr><td>Check-in</td><td>{{check_in_date}}</td></tr><tr><td>Check-out</td><td>{{check_out_date}}</td></tr><tr><td>Subtotal</td><td>{{subtotal}}</td></tr><tr><td>Tax</td><td>{{tax_amount}}</td></tr><tr><td><strong>Total</strong></td><td><strong>{{total_amount}}</strong></td></tr></table>",
"footerText": "Thank you for staying with us! — {{organization_name}}",
"isDefault": false,
"orgId": "663f1a2b3c4d5e6f7a8b9c0d",
"createdAt": "2026-02-23T11:00:00.000Z",
"updatedAt": "2026-02-23T11:00:00.000Z"
}
}Get Template by ID
GET /api/email-templates/:orgId/:templateIdResponse — 200 OK
json
{
"success": true,
"data": {
"_id": "66611b2c3d4e5f6a7b8c9d11",
"name": "Detailed Invoice",
"type": "invoice",
"subject": "Invoice {{invoice_number}} — {{organization_name}}",
"headerColor": "#1a73e8",
"headerText": "Tax Invoice",
"bodyHtml": "<p>Dear {{guest_name}},</p><p>Please find your invoice <strong>{{invoice_number}}</strong> dated {{invoice_date}} attached.</p><table><tr><td>Room</td><td>{{room_number}}</td></tr><tr><td>Check-in</td><td>{{check_in_date}}</td></tr><tr><td>Check-out</td><td>{{check_out_date}}</td></tr><tr><td>Subtotal</td><td>{{subtotal}}</td></tr><tr><td>Tax</td><td>{{tax_amount}}</td></tr><tr><td><strong>Total</strong></td><td><strong>{{total_amount}}</strong></td></tr></table>",
"footerText": "Thank you for staying with us! — {{organization_name}}",
"isDefault": false,
"orgId": "663f1a2b3c4d5e6f7a8b9c0d",
"createdAt": "2026-02-23T11:00:00.000Z",
"updatedAt": "2026-02-23T11:00:00.000Z"
}
}Update Template
PUT /api/email-templates/:orgId/:templateId/updateRequest Body
json
{
"name": "Detailed Invoice v2",
"subject": "Invoice {{invoice_number}} — Due {{due_date}}",
"headerColor": "#0d47a1",
"footerText": "Payment due by {{due_date}}. Contact us at {{organization_email}}."
}Response — 200 OK
json
{
"success": true,
"message": "Email template updated successfully",
"data": {
"_id": "66611b2c3d4e5f6a7b8c9d11",
"name": "Detailed Invoice v2",
"type": "invoice",
"subject": "Invoice {{invoice_number}} — Due {{due_date}}",
"headerColor": "#0d47a1",
"headerText": "Tax Invoice",
"bodyHtml": "<p>Dear {{guest_name}},</p>...",
"footerText": "Payment due by {{due_date}}. Contact us at {{organization_email}}.",
"isDefault": false,
"orgId": "663f1a2b3c4d5e6f7a8b9c0d",
"createdAt": "2026-02-23T11:00:00.000Z",
"updatedAt": "2026-02-23T13:00:00.000Z"
}
}Delete Template
DELETE /api/email-templates/:orgId/:templateId/deleteResponse — 200 OK
json
{
"success": true,
"message": "Email template deleted successfully"
}Preview Template
POST /api/email-templates/:orgId/:templateId/previewRenders the template with sample data. Optionally override specific variables.
Request Body
json
{
"sampleData": {
"invoice_number": "INV-1042",
"invoice_date": "2026-02-23",
"due_date": "2026-03-05",
"guest_name": "Arjun Mehta",
"guest_email": "arjun@example.com",
"room_number": "101",
"check_in_date": "2026-02-20",
"check_out_date": "2026-02-23",
"subtotal": "₹15,000",
"tax_amount": "₹2,700",
"total_amount": "₹17,700",
"organization_name": "Grand Palace Hotel",
"organization_email": "info@grandpalace.com",
"organization_phone": "+91-9876543210",
"organization_address": "12 Marine Drive, Mumbai"
}
}Response — 200 OK
json
{
"success": true,
"data": {
"subject": "Invoice INV-1042 — Due 2026-03-05",
"html": "<div style=\"background:#0d47a1;color:#fff;padding:20px\"><h1>Tax Invoice</h1></div><p>Dear Arjun Mehta,</p><p>Please find your invoice <strong>INV-1042</strong> dated 2026-02-23 attached.</p><table><tr><td>Room</td><td>101</td></tr><tr><td>Check-in</td><td>2026-02-20</td></tr><tr><td>Check-out</td><td>2026-02-23</td></tr><tr><td>Subtotal</td><td>₹15,000</td></tr><tr><td>Tax</td><td>₹2,700</td></tr><tr><td><strong>Total</strong></td><td><strong>₹17,700</strong></td></tr></table><footer>Payment due by 2026-03-05. Contact us at info@grandpalace.com.</footer>"
}
}Set Default Template
POST /api/email-templates/:orgId/:templateId/set-defaultSets this template as the default for its type. Any previously default template of the same type is unset.
Response — 200 OK
json
{
"success": true,
"message": "Template set as default for type 'invoice'",
"data": {
"_id": "66611b2c3d4e5f6a7b8c9d11",
"name": "Detailed Invoice v2",
"type": "invoice",
"isDefault": true
}
}