curl -X POST https://api2.ecomailapp.cz/templates \
-H "key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "New Template",
"html": "<b>Template HTML</b>"
}'
curl -X POST https://api2.ecomailapp.cz/templates \
-H "key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "New MJML Template",
"mjml": {
"tagName": "mj-body",
"attributes": {},
"children": [
{
"tagName": "mj-section",
"children": [
{
"tagName": "mj-column",
"children": [
{ "tagName": "mj-text", "content": "Hello from the API" }
]
}
]
}
]
}
}'
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api2.ecomailapp.cz/templates');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'key: YOUR_API_KEY',
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'name' => 'New Template',
'html' => '<b>Template HTML</b>',
]));
$response = curl_exec($ch);
curl_close($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api2.ecomailapp.cz/templates');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'key: YOUR_API_KEY',
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'name' => 'New MJML Template',
'mjml' => [
'tagName' => 'mj-body',
'attributes' => (object) [],
'children' => [
[
'tagName' => 'mj-section',
'children' => [
[
'tagName' => 'mj-column',
'children' => [
['tagName' => 'mj-text', 'content' => 'Hello from the API'],
],
],
],
],
],
],
]));
$response = curl_exec($ch);
curl_close($ch);
{
"id": 1,
"name": "New Template",
"html": "<b>Template HTML</b>"
}
{
"error": "The mjml definition could not be rendered to html."
}
Templates
Create a new template
Create a new email template from HTML or from an MJML definition.
POST
/
templates
curl -X POST https://api2.ecomailapp.cz/templates \
-H "key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "New Template",
"html": "<b>Template HTML</b>"
}'
curl -X POST https://api2.ecomailapp.cz/templates \
-H "key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "New MJML Template",
"mjml": {
"tagName": "mj-body",
"attributes": {},
"children": [
{
"tagName": "mj-section",
"children": [
{
"tagName": "mj-column",
"children": [
{ "tagName": "mj-text", "content": "Hello from the API" }
]
}
]
}
]
}
}'
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api2.ecomailapp.cz/templates');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'key: YOUR_API_KEY',
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'name' => 'New Template',
'html' => '<b>Template HTML</b>',
]));
$response = curl_exec($ch);
curl_close($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api2.ecomailapp.cz/templates');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'key: YOUR_API_KEY',
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'name' => 'New MJML Template',
'mjml' => [
'tagName' => 'mj-body',
'attributes' => (object) [],
'children' => [
[
'tagName' => 'mj-section',
'children' => [
[
'tagName' => 'mj-column',
'children' => [
['tagName' => 'mj-text', 'content' => 'Hello from the API'],
],
],
],
],
],
],
]));
$response = curl_exec($ch);
curl_close($ch);
{
"id": 1,
"name": "New Template",
"html": "<b>Template HTML</b>"
}
{
"error": "The mjml definition could not be rendered to html."
}
Create a template from raw HTML, or from an MJML definition. Send exactly one of
html and mjml.
A template created from an MJML definition is editable in the Ecomail drag-and-drop editor. Ecomail compiles the definition to HTML for you, so the template is ready to send right away. A template created from raw HTML is editable only in the code editor.
string
required
Template name.
string
Template HTML content. Required when
mjml is not sent. Do not combine with mjml.object
MJML definition of the template, in the same JSON format the Ecomail editor uses. Required when
html is not sent.The definition is a tree of nodes. Each node has a tagName (an MJML component such as mj-section, mj-column, mj-text, mj-image, or mj-button), optional attributes, and either children or content. The root node must contain a children array.curl -X POST https://api2.ecomailapp.cz/templates \
-H "key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "New Template",
"html": "<b>Template HTML</b>"
}'
curl -X POST https://api2.ecomailapp.cz/templates \
-H "key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "New MJML Template",
"mjml": {
"tagName": "mj-body",
"attributes": {},
"children": [
{
"tagName": "mj-section",
"children": [
{
"tagName": "mj-column",
"children": [
{ "tagName": "mj-text", "content": "Hello from the API" }
]
}
]
}
]
}
}'
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api2.ecomailapp.cz/templates');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'key: YOUR_API_KEY',
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'name' => 'New Template',
'html' => '<b>Template HTML</b>',
]));
$response = curl_exec($ch);
curl_close($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api2.ecomailapp.cz/templates');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'key: YOUR_API_KEY',
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'name' => 'New MJML Template',
'mjml' => [
'tagName' => 'mj-body',
'attributes' => (object) [],
'children' => [
[
'tagName' => 'mj-section',
'children' => [
[
'tagName' => 'mj-column',
'children' => [
['tagName' => 'mj-text', 'content' => 'Hello from the API'],
],
],
],
],
],
],
]));
$response = curl_exec($ch);
curl_close($ch);
{
"id": 1,
"name": "New Template",
"html": "<b>Template HTML</b>"
}
{
"error": "The mjml definition could not be rendered to html."
}