Create an email template
Creates a Liquid email template. Variables are auto-extracted when omitted.
curl --request POST \
--url https://api.telnyx.com/v2/email_templates \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Welcome Email",
"subject": "Welcome, {{ first_name }}!",
"html_body": "<h1>Hello {{ first_name }}</h1>",
"text_body": "Hello {{ first_name }}"
}
'import requests
url = "https://api.telnyx.com/v2/email_templates"
payload = {
"name": "Welcome Email",
"subject": "Welcome, {{ first_name }}!",
"html_body": "<h1>Hello {{ first_name }}</h1>",
"text_body": "Hello {{ first_name }}"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Welcome Email',
subject: 'Welcome, {{ first_name }}!',
html_body: '<h1>Hello {{ first_name }}</h1>',
text_body: 'Hello {{ first_name }}'
})
};
fetch('https://api.telnyx.com/v2/email_templates', 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://api.telnyx.com/v2/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 => json_encode([
'name' => 'Welcome Email',
'subject' => 'Welcome, {{ first_name }}!',
'html_body' => '<h1>Hello {{ first_name }}</h1>',
'text_body' => 'Hello {{ first_name }}'
]),
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.telnyx.com/v2/email_templates"
payload := strings.NewReader("{\n \"name\": \"Welcome Email\",\n \"subject\": \"Welcome, {{ first_name }}!\",\n \"html_body\": \"<h1>Hello {{ first_name }}</h1>\",\n \"text_body\": \"Hello {{ first_name }}\"\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))
}HttpResponse<String> response = Unirest.post("https://api.telnyx.com/v2/email_templates")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Welcome Email\",\n \"subject\": \"Welcome, {{ first_name }}!\",\n \"html_body\": \"<h1>Hello {{ first_name }}</h1>\",\n \"text_body\": \"Hello {{ first_name }}\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.telnyx.com/v2/email_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\": \"Welcome Email\",\n \"subject\": \"Welcome, {{ first_name }}!\",\n \"html_body\": \"<h1>Hello {{ first_name }}</h1>\",\n \"text_body\": \"Hello {{ first_name }}\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"record_type": "email_template",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>",
"subject": "<string>",
"html_body": "<string>",
"text_body": "<string>",
"variables": [
"<string>"
],
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}
}{
"errors": [
{
"code": "10015",
"title": "Bad Request",
"detail": "email is required"
}
]
}{
"errors": [
{
"code": "10006",
"title": "Not authorized",
"detail": "Invalid API key",
"meta": {
"url": "https://developers.telnyx.com/docs/overview/errors/10006"
}
}
]
}{
"errors": [
{
"code": "10036",
"title": "Resource is being processed",
"detail": "A request with this Idempotency-Key is already being processed.",
"source": {
"pointer": "/header/Idempotency-Key"
}
}
]
}{
"errors": [
{
"title": "<string>",
"detail": "<string>",
"source": {},
"meta": {}
}
],
"suppressed": [
{
"to": "jsmith@example.com",
"reason": "<string>",
"scope": "<string>",
"override_allowed": true
}
]
}{
"errors": [
{
"code": "10015",
"title": "Validation Failed",
"detail": "subject can't be blank",
"source": {
"pointer": "/data/attributes/subject"
}
}
]
}{
"errors": [
{
"code": "10016",
"title": "Service Unavailable",
"detail": "The email domain service is temporarily unavailable. Please try again later."
}
]
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Headers
Optional opaque, unquoted key for safely retrying the same logical request. Keys must contain 1 to 255 letters, numbers, hyphens, or underscores. Generate a unique UUID v4 for each operation and reuse it only when retrying that operation with the same request. Invalid headers—including duplicate, empty, malformed, or overlong values—return 400 with error code 10015. A request already in progress with the same key returns 409; reusing the key with a different request returns 422. Only successful responses are replayed, for up to 24 hours. Do not include sensitive data in the key.
1 - 255^[A-Za-z0-9_-]{1,255}$Body
Letters, numbers, spaces, hyphens, and underscores only.
^[A-Za-z0-9 _-]+$Liquid template subject.
Liquid template HTML body.
Liquid template text body.
Template variables. Auto-extracted from subject/body fields when absent.
Response
Template created.
Show child attributes
Show child attributes
Was this page helpful?
curl --request POST \
--url https://api.telnyx.com/v2/email_templates \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Welcome Email",
"subject": "Welcome, {{ first_name }}!",
"html_body": "<h1>Hello {{ first_name }}</h1>",
"text_body": "Hello {{ first_name }}"
}
'import requests
url = "https://api.telnyx.com/v2/email_templates"
payload = {
"name": "Welcome Email",
"subject": "Welcome, {{ first_name }}!",
"html_body": "<h1>Hello {{ first_name }}</h1>",
"text_body": "Hello {{ first_name }}"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Welcome Email',
subject: 'Welcome, {{ first_name }}!',
html_body: '<h1>Hello {{ first_name }}</h1>',
text_body: 'Hello {{ first_name }}'
})
};
fetch('https://api.telnyx.com/v2/email_templates', 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://api.telnyx.com/v2/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 => json_encode([
'name' => 'Welcome Email',
'subject' => 'Welcome, {{ first_name }}!',
'html_body' => '<h1>Hello {{ first_name }}</h1>',
'text_body' => 'Hello {{ first_name }}'
]),
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.telnyx.com/v2/email_templates"
payload := strings.NewReader("{\n \"name\": \"Welcome Email\",\n \"subject\": \"Welcome, {{ first_name }}!\",\n \"html_body\": \"<h1>Hello {{ first_name }}</h1>\",\n \"text_body\": \"Hello {{ first_name }}\"\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))
}HttpResponse<String> response = Unirest.post("https://api.telnyx.com/v2/email_templates")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Welcome Email\",\n \"subject\": \"Welcome, {{ first_name }}!\",\n \"html_body\": \"<h1>Hello {{ first_name }}</h1>\",\n \"text_body\": \"Hello {{ first_name }}\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.telnyx.com/v2/email_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\": \"Welcome Email\",\n \"subject\": \"Welcome, {{ first_name }}!\",\n \"html_body\": \"<h1>Hello {{ first_name }}</h1>\",\n \"text_body\": \"Hello {{ first_name }}\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"record_type": "email_template",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>",
"subject": "<string>",
"html_body": "<string>",
"text_body": "<string>",
"variables": [
"<string>"
],
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}
}{
"errors": [
{
"code": "10015",
"title": "Bad Request",
"detail": "email is required"
}
]
}{
"errors": [
{
"code": "10006",
"title": "Not authorized",
"detail": "Invalid API key",
"meta": {
"url": "https://developers.telnyx.com/docs/overview/errors/10006"
}
}
]
}{
"errors": [
{
"code": "10036",
"title": "Resource is being processed",
"detail": "A request with this Idempotency-Key is already being processed.",
"source": {
"pointer": "/header/Idempotency-Key"
}
}
]
}{
"errors": [
{
"title": "<string>",
"detail": "<string>",
"source": {},
"meta": {}
}
],
"suppressed": [
{
"to": "jsmith@example.com",
"reason": "<string>",
"scope": "<string>",
"override_allowed": true
}
]
}{
"errors": [
{
"code": "10015",
"title": "Validation Failed",
"detail": "subject can't be blank",
"source": {
"pointer": "/data/attributes/subject"
}
}
]
}{
"errors": [
{
"code": "10016",
"title": "Service Unavailable",
"detail": "The email domain service is temporarily unavailable. Please try again later."
}
]
}