Create template
This method creates a template in the brand your API key belongs to.
URL
https://dashboard.skry.be/api/templates/create-template.php
PARAMETERS(POST)
api_keyyour API key.namethe name of the template.html_textthe HTML of the template.plain_textthe plain-text version. (optional)from_namethe From name to save with the template. (optional)from_emailthe From email to save with the template. Its domain must be one of the brand's allowed sending domains. (optional)reply_tothe Reply-to address to save with the template. (optional)editorthe editor the app opens the template in:htmlordragdrop. Default ishtml, since HTML sent through the API is usually hand-written and the drag-and-drop editor can reshape it. (optional)
RESPONSE (JSON)
Success: the new template, without its HTML.
{
"id": 12,
"name": "Monthly newsletter",
"from_name": "Acme",
"from_email": "news@acme.com",
"reply_to": "hello@acme.com",
"editor": "html"
}
idthe template's numeric idnamethe template's namefrom_name,from_email,reply_tothe sender details saved with the template (empty strings if not set)editorwhich editor the app opens the template in:html(the code editor) ordragdrop
Error: No data passed
Error: API key not passed
Error: Invalid API key
Error: Brand does not exist
Error: Template name not passed
Error: HTML not passed
Error: A field is too long: <field> (at most <n> characters)
Error: Template name cannot be empty
Error: HTML cannot be empty
Error: Invalid from_email
Error: Unauthorised From email domain
Error: Invalid reply_to
Error: editor must be html or dragdrop
Error: Unable to create template
name can be up to 500 characters, and from_name, from_email and reply_to up to 100 each. When a field is too long, the error names it, eg. A field is too long: from_name (at most 100 characters).
Unauthorised From email domain means from_email isn't on one of the brand's allowed sending domains (the same check the app makes when you save a template).
Brand does not exist is returned when the key isn't tied to a brand, for example the main account's key.
EXAMPLES
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");
var urlencoded = new URLSearchParams();
urlencoded.append("api_key", "<YOUR_API_KEY>");
urlencoded.append("name", "Monthly newsletter");
urlencoded.append("html_text", "<html><body><h1>Hello [Name,fallback=there]</h1></body></html>");
urlencoded.append("from_name", "Acme");
urlencoded.append("from_email", "news@acme.com");
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: urlencoded,
redirect: 'follow'
};
fetch("https://dashboard.skry.be/api/templates/create-template.php", requestOptions)
.then(response => response.text())
// Success is JSON; errors are plain text
.then(text => {
try { console.log(JSON.parse(text)); }
catch (e) { console.log('error', text); }
})
.catch(error => console.log('error', error));
const axios = require('axios');
const qs = require('qs');
let data = qs.stringify({
'api_key': '<YOUR_API_KEY>',
'name': 'Monthly newsletter',
'html_text': '<html><body><h1>Hello [Name,fallback=there]</h1></body></html>',
'from_name': 'Acme',
'from_email': 'news@acme.com'
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://dashboard.skry.be/api/templates/create-template.php',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});