Create a template
curl --request POST \
--url https://api.sendbaze.com/v1/templates \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "order-shipped",
"subject": "Your order {{order_id}} has shipped",
"html": "<p>Hi {{name}},</p><p>Order <b>{{order_id}}</b> arrives by {{eta}}.</p>",
"text": "Hi {{name}}, order {{order_id}} arrives by {{eta}}."
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'order-shipped',
subject: 'Your order {{order_id}} has shipped',
html: '<p>Hi {{name}},</p><p>Order <b>{{order_id}}</b> arrives by {{eta}}.</p>',
text: 'Hi {{name}}, order {{order_id}} arrives by {{eta}}.'
})
};
fetch('https://api.sendbaze.com/v1/templates', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.sendbaze.com/v1/templates"
payload = {
"name": "order-shipped",
"subject": "Your order {{order_id}} has shipped",
"html": "<p>Hi {{name}},</p><p>Order <b>{{order_id}}</b> arrives by {{eta}}.</p>",
"text": "Hi {{name}}, order {{order_id}} arrives by {{eta}}."
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)require 'uri'
require 'net/http'
url = URI("https://api.sendbaze.com/v1/templates")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"order-shipped\",\n \"subject\": \"Your order {{order_id}} has shipped\",\n \"html\": \"<p>Hi {{name}},</p><p>Order <b>{{order_id}}</b> arrives by {{eta}}.</p>\",\n \"text\": \"Hi {{name}}, order {{order_id}} arrives by {{eta}}.\"\n}"
response = http.request(request)
puts response.read_body<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.sendbaze.com/v1/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 => json_encode([
'name' => 'order-shipped',
'subject' => 'Your order {{order_id}} has shipped',
'html' => '<p>Hi {{name}},</p><p>Order <b>{{order_id}}</b> arrives by {{eta}}.</p>',
'text' => 'Hi {{name}}, order {{order_id}} arrives by {{eta}}.'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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://api.sendbaze.com/v1/templates"
payload := strings.NewReader("{\n \"name\": \"order-shipped\",\n \"subject\": \"Your order {{order_id}} has shipped\",\n \"html\": \"<p>Hi {{name}},</p><p>Order <b>{{order_id}}</b> arrives by {{eta}}.</p>\",\n \"text\": \"Hi {{name}}, order {{order_id}} arrives by {{eta}}.\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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": "tpl_01j9x7k2r4m8q3v5n6b7c8d9e0",
"name": "order-shipped",
"subject": "<string>",
"html": "<string>",
"text": "<string>",
"variables": [
"order_id",
"name",
"eta"
],
"version": 1,
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
}{
"error": {
"code": "validation_error",
"message": "<string>",
"docs": "<string>",
"fields": {},
"limit": 123,
"upgradeUrl": "<string>",
"topUpUrl": "<string>",
"settingsUrl": "<string>",
"domainsUrl": "<string>"
}
}{
"error": {
"code": "validation_error",
"message": "<string>",
"docs": "<string>",
"fields": {},
"limit": 123,
"upgradeUrl": "<string>",
"topUpUrl": "<string>",
"settingsUrl": "<string>",
"domainsUrl": "<string>"
}
}{
"error": {
"code": "validation_error",
"message": "The request has invalid fields.",
"docs": "https://docs.sendbaze.com/errors#validation_error",
"fields": {
"to.1": [
"must be a valid email address"
]
}
}
}Templates
Create a template
Creates version 1. The response lists the {{variables}} found in the subject, html and text.
A duplicate name is a 409. Requires emails:send.
POST
/
v1
/
templates
Create a template
curl --request POST \
--url https://api.sendbaze.com/v1/templates \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "order-shipped",
"subject": "Your order {{order_id}} has shipped",
"html": "<p>Hi {{name}},</p><p>Order <b>{{order_id}}</b> arrives by {{eta}}.</p>",
"text": "Hi {{name}}, order {{order_id}} arrives by {{eta}}."
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'order-shipped',
subject: 'Your order {{order_id}} has shipped',
html: '<p>Hi {{name}},</p><p>Order <b>{{order_id}}</b> arrives by {{eta}}.</p>',
text: 'Hi {{name}}, order {{order_id}} arrives by {{eta}}.'
})
};
fetch('https://api.sendbaze.com/v1/templates', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.sendbaze.com/v1/templates"
payload = {
"name": "order-shipped",
"subject": "Your order {{order_id}} has shipped",
"html": "<p>Hi {{name}},</p><p>Order <b>{{order_id}}</b> arrives by {{eta}}.</p>",
"text": "Hi {{name}}, order {{order_id}} arrives by {{eta}}."
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)require 'uri'
require 'net/http'
url = URI("https://api.sendbaze.com/v1/templates")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"order-shipped\",\n \"subject\": \"Your order {{order_id}} has shipped\",\n \"html\": \"<p>Hi {{name}},</p><p>Order <b>{{order_id}}</b> arrives by {{eta}}.</p>\",\n \"text\": \"Hi {{name}}, order {{order_id}} arrives by {{eta}}.\"\n}"
response = http.request(request)
puts response.read_body<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.sendbaze.com/v1/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 => json_encode([
'name' => 'order-shipped',
'subject' => 'Your order {{order_id}} has shipped',
'html' => '<p>Hi {{name}},</p><p>Order <b>{{order_id}}</b> arrives by {{eta}}.</p>',
'text' => 'Hi {{name}}, order {{order_id}} arrives by {{eta}}.'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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://api.sendbaze.com/v1/templates"
payload := strings.NewReader("{\n \"name\": \"order-shipped\",\n \"subject\": \"Your order {{order_id}} has shipped\",\n \"html\": \"<p>Hi {{name}},</p><p>Order <b>{{order_id}}</b> arrives by {{eta}}.</p>\",\n \"text\": \"Hi {{name}}, order {{order_id}} arrives by {{eta}}.\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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": "tpl_01j9x7k2r4m8q3v5n6b7c8d9e0",
"name": "order-shipped",
"subject": "<string>",
"html": "<string>",
"text": "<string>",
"variables": [
"order_id",
"name",
"eta"
],
"version": 1,
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
}{
"error": {
"code": "validation_error",
"message": "<string>",
"docs": "<string>",
"fields": {},
"limit": 123,
"upgradeUrl": "<string>",
"topUpUrl": "<string>",
"settingsUrl": "<string>",
"domainsUrl": "<string>"
}
}{
"error": {
"code": "validation_error",
"message": "<string>",
"docs": "<string>",
"fields": {},
"limit": 123,
"upgradeUrl": "<string>",
"topUpUrl": "<string>",
"settingsUrl": "<string>",
"domainsUrl": "<string>"
}
}{
"error": {
"code": "validation_error",
"message": "The request has invalid fields.",
"docs": "https://docs.sendbaze.com/errors#validation_error",
"fields": {
"to.1": [
"must be a valid email address"
]
}
}
}Authorizations
An API key from the dashboard. sk_live_… sends; sk_test_… validates and returns ids without sending.
Body
application/json
Response
Created
Example:
"tpl_01j9x7k2r4m8q3v5n6b7c8d9e0"
Example:
"order-shipped"
Placeholder names found in the subject, html and text.
Example:
["order_id", "name", "eta"]
Example:
1