Create Template
curl --request POST \
--url https://cloudapi.mailercloud.com/v1/templates/create \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"categoryId": 0,
"html": "<html><body> Sample HTML </body></html>",
"name": "New Template",
"plainText": "Sample HTML"
}
'import requests
url = "https://cloudapi.mailercloud.com/v1/templates/create"
payload = {
"categoryId": 0,
"html": "<html><body> Sample HTML </body></html>",
"name": "New Template",
"plainText": "Sample HTML"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
categoryId: 0,
html: '<html><body> Sample HTML </body></html>',
name: 'New Template',
plainText: 'Sample HTML'
})
};
fetch('https://cloudapi.mailercloud.com/v1/templates/create', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://cloudapi.mailercloud.com/v1/templates/create",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'categoryId' => 0,
'html' => '<html><body> Sample HTML </body></html>',
'name' => 'New Template',
'plainText' => 'Sample HTML'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <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;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://cloudapi.mailercloud.com/v1/templates/create"
payload := strings.NewReader("{\n \"categoryId\": 0,\n \"html\": \"<html><body> Sample HTML </body></html>\",\n \"name\": \"New Template\",\n \"plainText\": \"Sample HTML\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"id": "EyK"
}{
"error": "html is a required field"
}{
"errors": [
{
"field": "",
"message": "Authorization failed"
}
]
}Create Template
API to create a new template in Mailercloud.
Required Fields:
-
name: Name of the template (required, max 100 characters, must be unique)
-
html: Specifies the HTML content (required)
Optional Fields:
-
categoryId: Specifies the category ID of the template, you can get it from the Get Template Categories API. It would be 0 by default.
-
plainText: Specifies the plain text content
POST
/
templates
/
create
Create Template
curl --request POST \
--url https://cloudapi.mailercloud.com/v1/templates/create \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"categoryId": 0,
"html": "<html><body> Sample HTML </body></html>",
"name": "New Template",
"plainText": "Sample HTML"
}
'import requests
url = "https://cloudapi.mailercloud.com/v1/templates/create"
payload = {
"categoryId": 0,
"html": "<html><body> Sample HTML </body></html>",
"name": "New Template",
"plainText": "Sample HTML"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
categoryId: 0,
html: '<html><body> Sample HTML </body></html>',
name: 'New Template',
plainText: 'Sample HTML'
})
};
fetch('https://cloudapi.mailercloud.com/v1/templates/create', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://cloudapi.mailercloud.com/v1/templates/create",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'categoryId' => 0,
'html' => '<html><body> Sample HTML </body></html>',
'name' => 'New Template',
'plainText' => 'Sample HTML'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <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;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://cloudapi.mailercloud.com/v1/templates/create"
payload := strings.NewReader("{\n \"categoryId\": 0,\n \"html\": \"<html><body> Sample HTML </body></html>\",\n \"name\": \"New Template\",\n \"plainText\": \"Sample HTML\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"id": "EyK"
}{
"error": "html is a required field"
}{
"errors": [
{
"field": "",
"message": "Authorization failed"
}
]
}Authorizations
Your Mailercloud API key (plain text, no Bearer prefix). Create keys in Settings → API.
Headers
Request body type
Response
Created
The response is of type object.
⌘I