Create a Template
POST/v1/templates
Request Body
Email subject (supports variables)
HTML content (supports variables)
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
{
"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:
<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
{
"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"