Create email template
Create customized email templates using API. Personalize your emails with your own or 3rd party app.
POST
/email-templates/
Data
Type
Description
name
string
Name your template to easily identify it
content
string
Content of your email template (HTML can be used inside)
desc
string
Description of your email template
curl -X POST -H "Authorization: Token <your_64_char_api_key>" -H "Content-Type: application/json" -d '{
"name":"Test template",
"content":"<body><p>My test email template</p></body>",
"desc":"This is email template created for test. Don'"'"'t send it to users."
}' "https://<your_app_subdomain>.user.com/api/public/email-templates/"
Response
{
"id": 213,
"name": "Test template",
"desc": "This is email template created for test. Don't send it to users.",
"created_at": "2016-09-19T09:08:53.125485Z",
"updated_at": "2016-09-19T09:08:53.125518Z",
"content": "<body><p>My test email template</p></body>"
}
var settings = {
"async": true,
"crossDomain": true,
"url": "https://<your_app_subdomain>.user.com/api/public/email-templates/",
"method": "POST",
"headers": {
"authorization": "Token |<your_64_char_api_key>",
"content-type": "application/json"
},
"processData": false,
"data": "{\r\n\t\"name\":\"Test template\",\r\n\t\"content\":\"<body><p>My test email template</p></body>\",\r\n\t\"desc\":\"This is email template created for test. Don't send it to users.\"\r\n}"
}
$.ajax(settings).done(function (response) {
console.log(response);
});
var data = JSON.stringify({
"name": "Test template",
"content": "<body><p>My test email template</p></body>",
"desc": "This is email template created for test. Don't send it to users."
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://<your_app_subdomain>.user.com/api/public/email-templates/");
xhr.setRequestHeader("authorization", "Token <your_64_char_api_key>");
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
var request = require("request");
var options = { method: 'POST',
url: 'https://<your_app_subdomain>.user.com/api/public/email-templates/',
headers:
{ 'content-type': 'application/json',
authorization: 'Token <your_64_char_api_key>' },
body:
{ name: 'Test template',
content: '<body><p>My test email template</p></body>',
desc: 'This is email template created for test. Don\'t send it to users.' },
json: true };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://<your_app_subdomain>.user.com/api/public/email-templates/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\r\n \"name\":\"Test template\",\r\n \"content\":\"<body><p>My test email template</p></body>\",\r\n \"desc\":\"This is email template created for test. Don't send it to users.\"\r\n}",
CURLOPT_HTTPHEADER => array(
"authorization: Token <your_64_char_api_key>",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
import requests
url = "https://<your_app_subdomain>.user.com/api/public/email-templates/"
payload = "{\r\n\t\"name\":\"Test template\",\r\n\t\"content\":\"<body><p>My test email template</p></body>\",\r\n\t\"desc\":\"This is email template created for test. Don't send it to users.\"\r\n}"
headers = {
'authorization': "Token <your_64_char_api_key>",
'content-type': "application/json"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
import http.client
conn = http.client.HTTPSConnection("<your_app_subdomain>.user.com")
payload = "{\r\n\t\"name\":\"Test template\",\r\n\t\"content\":\"<body><p>My test email template</p></body>\",\r\n\t\"desc\":\"This is email template created for test. Don't send it to users.\"\r\n}"
headers = {
'authorization': "Token <your_64_char_api_key>",
'content-type': "application/json"
}
conn.request("POST", "/api/public/email-templates/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))