REST APITemplates

Templates Endpoints

Create, manage, and use reusable email templates with dynamic variables.

GET/api/templates

List Templates

Retrieve all email templates with pagination.

Query Parameters

ParameterTypeDescription
pagenumberPage number (default: 1)
limitnumberItems per page (default: 20)
searchstringSearch by template name

Example Request

curlTerminal
1
2
curl -X GET "https://api.metigan.com/api/templates?page=1&limit=20" \
  -H "x-api-key: your_api_key"

Response

200 OKJSON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
  "success": true,
  "templates": [
    {
      "id": "tpl_abc123",
      "name": "Welcome Email",
      "subject": "Welcome to {{appName}}!",
      "createdAt": "2024-01-19T10:30:00Z",
      "updatedAt": "2024-01-19T10:30:00Z"
    },
    {
      "id": "tpl_def456",
      "name": "Order Confirmation",
      "subject": "Order Confirmed #{{orderId}}",
      "createdAt": "2024-01-15T08:00:00Z",
      "updatedAt": "2024-01-18T12:00:00Z"
    }
  ],
  "pagination": {
    "total": 15,
    "page": 1,
    "limit": 20,
    "pages": 1
  }
}
GET/api/templates/:id

Get Template

Retrieve a single template with all its components and styles.

Example Request

curlTerminal
1
2
curl -X GET https://api.metigan.com/api/templates/tpl_abc123 \
  -H "x-api-key: your_api_key"

Response

200 OKJSON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{
  "success": true,
  "data": {
    "id": "tpl_abc123",
    "name": "Welcome Email",
    "subject": "Welcome to {{appName}}!",
    "components": [
      {
        "id": "header-1",
        "type": "heading",
        "content": "Welcome, {{firstName}}!",
        "styles": {
          "fontSize": 24,
          "fontWeight": "bold",
          "textAlign": "center"
        }
      },
      {
        "id": "text-1",
        "type": "text",
        "content": "Thank you for joining {{appName}}. We're excited to have you!",
        "styles": {
          "fontSize": 16,
          "textAlign": "left"
        }
      },
      {
        "id": "button-1",
        "type": "button",
        "label": "Get Started",
        "url": "{{dashboardUrl}}",
        "styles": {
          "backgroundColor": "#4F46E5",
          "color": "#FFFFFF",
          "borderRadius": 8
        }
      }
    ],
    "styles": {
      "backgroundColor": "#FFFFFF",
      "width": 600,
      "padding": 20
    },
    "createdAt": "2024-01-19T10:30:00Z",
    "updatedAt": "2024-01-19T10:30:00Z"
  }
}
POST/api/templates/:id/render

Render Template

Render a template with variables to preview the final HTML output.

Request Body

FieldTypeDescription
variablesobjectKey-value pairs for variable substitution

Example Request

curlTerminal
1
2
3
4
5
6
7
8
9
10
curl -X POST https://api.metigan.com/api/templates/tpl_abc123/render \
  -H "x-api-key: your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "variables": {
      "firstName": "John",
      "appName": "MyApp",
      "dashboardUrl": "https://app.myapp.com/dashboard"
    }
  }'

Response

200 OKJSON
1
2
3
4
5
{
  "success": true,
  "html": "<!DOCTYPE html><html>...</html>",
  "subject": "Welcome to MyApp!"
}

Template Variables

Use double curly braces to define variables in your templates:

template-example.htmlHTML
1
2
3
4
5
6
7
8
9
10
11
12
13
<h1>Welcome, {{firstName}}!</h1>
<p>Thank you for signing up for {{appName}}.</p>
<p>Your account email: {{email}}</p>

<a href="{{verificationLink}}">Verify Your Email</a>

<!-- Conditional content -->
{{#if isPremium}}
  <p>Enjoy your premium features!</p>
{{/if}}

<!-- Default values -->
<p>Company: {{company|"Not specified"}}</p>

Built-in Variables

These variables are automatically available in all templates:

VariableDescription
{{unsubscribeUrl}}One-click unsubscribe link
{{preferencesUrl}}Email preferences page link
{{currentYear}}Current year (e.g., 2024)
{{currentDate}}Current date formatted

Using Templates with Email

To send an email using a template, pass the templateId andvariables to the email send endpoint:

curlTerminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
curl -X POST https://api.metigan.com/api/email/send \
  -H "x-api-key: your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "YourApp <noreply@yourapp.com>",
    "recipients": ["user@example.com"],
    "subject": "Welcome to YourApp!",
    "templateId": "tpl_abc123",
    "variables": {
      "firstName": "John",
      "appName": "YourApp",
      "dashboardUrl": "https://yourapp.com/dashboard"
    }
  }'
Subject Override

If you provide a subject in the request, it will override the template's default subject. The subject can also contain variables.

DELETE/api/templates/:id

Delete Template

Delete an email template.

Example Request

curlTerminal
1
2
curl -X DELETE https://api.metigan.com/api/templates/tpl_abc123 \
  -H "x-api-key: your_api_key"

Response

200 OKJSON
1
2
3
4
{
  "success": true,
  "message": "Template deleted successfully"
}