Create Template
Save a reusable email template. The returned id can be passed as template_id to POST /email/send — recipients receive the template's HTML with {{variables}} substituted from the request's variables map.
Endpoint
POST /templates
Returns: 201 Created
Headers
| Header | Value | Required |
|---|---|---|
Authorization | Bearer <your-api-key> | Yes |
Content-Type | application/json | Yes |
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Display name. Max 255 characters. |
html | string | Yes | Email body HTML. Supports {{variables}} for personalization. |
HTML is sanitized
The HTML you submit is run through a sanitizer (scripts, event handlers, and external resources are stripped) and Arsel's unsubscribe placeholders are auto-injected. The stored HTML returned in the response may differ from what you sent.
Response
{
"id": "01957e3a-4b5c-7d8e-9f0a-1b2c3d4e5f6a",
"name": "Welcome Email v2",
"html": "<h1>Welcome!</h1><p>Thanks for signing up.</p>",
"created_at": "2026-03-08T12:00:00.000Z",
"updated_at": "2026-03-08T12:00:00.000Z"
}
| Field | Type | Description |
|---|---|---|
id | string | Template ID. Use this as template_id in send/campaign requests. |
name | string | Template name |
html | string | Sanitized HTML body |
created_at | string | ISO 8601 timestamp |
updated_at | string | ISO 8601 timestamp |
Examples
- cURL
- JavaScript
- Python
- C#
- PHP
curl -X POST "https://api.arsel.sa/v1/templates" \
-H "Authorization: Bearer $ARSEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Welcome Email v2",
"html": "<h1>Welcome, {{first_name}}!</h1><p>Thanks for joining.</p>"
}'
const response = await fetch("https://api.arsel.sa/v1/templates", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ARSEL_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "Welcome Email v2",
html: "<h1>Welcome, {{first_name}}!</h1><p>Thanks for joining.</p>",
}),
});
const data = await response.json();
if (!response.ok) {
throw new Error(`${data.name}: ${data.message}`);
}
console.log(data);
import os
import requests
response = requests.post(
"https://api.arsel.sa/v1/templates",
headers={"Authorization": f"Bearer {os.environ['ARSEL_API_KEY']}"},
json={
"name": "Welcome Email v2",
"html": "<h1>Welcome, {{first_name}}!</h1><p>Thanks for joining.</p>",
},
)
response.raise_for_status()
print(response.json())
using System.Net.Http.Headers;
using System.Text;
var client = new HttpClient(); // share one instance across requests
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
"Bearer", Environment.GetEnvironmentVariable("ARSEL_API_KEY"));
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.arsel.sa/v1/templates")
{
Content = new StringContent(
"""
{
"name": "Welcome Email v2",
"html": "<h1>Welcome, {{first_name}}!</h1><p>Thanks for joining.</p>"
}
""",
Encoding.UTF8,
"application/json"),
};
var response = await client.SendAsync(request);
var body = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
throw new HttpRequestException($"{(int)response.StatusCode}: {body}");
Console.WriteLine(body);
<?php
$ch = curl_init("https://api.arsel.sa/v1/templates");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("ARSEL_API_KEY"),
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"name" => "Welcome Email v2",
"html" => "<h1>Welcome, {{first_name}}!</h1><p>Thanks for joining.</p>",
]),
]);
$data = json_decode(curl_exec($ch), true);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) >= 400) {
throw new Exception("{$data['name']}: {$data['message']}");
}
print_r($data);
Error Responses
- 422 Validation Error
- 401 Unauthorized
{
"status_code": 422,
"name": "validation_error",
"message": "name should not be empty, html should not be empty"
}
{
"status_code": 401,
"name": "unauthorized",
"message": "Invalid API Key"
}