Skip to main content

Create a Template

POST/v1/templates

Request Body

name
string
required
Template name
subject
string
required
Email subject (supports variables)
html
string
HTML content (supports variables)
text
string
Plain text version
variables
string[]
List of variable names used in the template
curl -X POST https://www.unosend.co/api/v1/templates \
  -H "Authorization: Bearer un_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Welcome Email",
    "subject": "Welcome to {{company_name}}, {{first_name}}!",
    "html": "<h1>Welcome, {{first_name}}!</h1><p>Thanks for joining {{company_name}}.</p>",
    "text": "Welcome, {{first_name}}! Thanks for joining {{company_name}}.",
    "variables": ["company_name", "first_name"]
  }'

Response

201 Created
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "Welcome Email",
  "subject": "Welcome to {{company_name}}, {{first_name}}!",
  "html": "<h1>Welcome, {{first_name}}!</h1><p>Thanks for joining {{company_name}}.</p>",
  "text": "Welcome, {{first_name}}! Thanks for joining {{company_name}}.",
  "variables": ["company_name", "first_name"],
  "created_at": "2024-01-15T10:30:00.000Z"
}

Variable Syntax

Use double curly braces for variables in your templates:
Template Example
<h1>Hello, {{first_name}}!</h1>
<p>Your order #{{order_id}} has been shipped.</p>
<p>Track it here: <a href="{{tracking_url}}">Track Order</a></p>
Variables are replaced with the values provided in template_data when sending an email.

List Templates

GET/v1/templates
curl https://www.unosend.co/api/v1/templates \
  -H "Authorization: Bearer un_your_api_key"

Response

200 OK
{
  "data": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "Welcome Email",
      "subject": "Welcome to {{company_name}}, {{first_name}}!",
      "html": "<h1>Welcome, {{first_name}}!</h1>...",
      "text": "Welcome, {{first_name}}!...",
      "variables": ["company_name", "first_name"],
      "created_at": "2024-01-15T10:30:00.000Z",
      "updated_at": "2024-01-15T10:30:00.000Z"
    }
  ]
}

Send Email with Template

Use the template_id parameter when sending emails:
curl -X POST https://www.unosend.co/api/v1/emails \
  -H "Authorization: Bearer un_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "[email protected]",
    "to": ["[email protected]"],
    "template_id": "550e8400-e29b-41d4-a716-446655440000",
    "template_data": {
      "first_name": "John",
      "company_name": "Acme Inc"
    }
  }'
When using a template, you don’t need to provide subject, html, or text fields - they are taken from the template.

Delete Template

DELETE/v1/templates/:id
curl -X DELETE https://www.unosend.co/api/v1/templates/550e8400-e29b-41d4-a716-446655440000 \
  -H "Authorization: Bearer un_your_api_key"