Create an email template
Creates a Liquid email template. Variables are auto-extracted when omitted.
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const EmailTemplate = await client.emailTemplates.create({
name: 'name',
});
console.log(EmailTemplate.data);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
email_template = client.email_templates.create(
name="name",
)
print(email_template.data)
package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
emailTemplate, err := client.EmailTemplates.New(
context.TODO(),
telnyx.EmailTemplateNewParams{
Name: "name",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", emailTemplate.Data)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.emailTemplates.EmailTemplateCreateParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
EmailTemplateCreateParams params = EmailTemplateCreateParams.builder()
.name("name")
.build();
var response = client.emailTemplates().create(params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
email_template = telnyx.email_templates.create(name: "name")
puts(email_template)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$email_template = $client->emailTemplates->create(
name: 'name',
);
var_dump($email_template);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx email-templates create \
--api-key 'My API Key' \
--name namecurl --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 }}"
}
'{
"data": {
"record_type": "email_template",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>",
"html_body": "<string>",
"text_body": "<string>",
"variables": [
"<string>"
],
"variables_mode": "automatic",
"strict_variables": true,
"autoescape": true,
"variable_schema": {},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"subject": "<string>"
}
}{
"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": [
{
"code": "10007",
"title": "Unexpected error",
"detail": "An unexpected error occured."
}
]
}{
"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
Telnyx API key supplied as Authorization: Bearer <token>. In production, auth may be validated by the API gateway and forwarded via Telnyx auth headers.
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.
255^[A-Za-z0-9 _-]+$Liquid template subject.
255Liquid template HTML body.
Liquid template text body.
Persisted variable names. In automatic mode a non-null array is rejected; in explicit mode this is the exact manual array and each item is limited to 255 Unicode code points.
255Controls how variables is maintained. If both fields are omitted (or variables is null), the template uses automatic mode and extracts variable names from the effective subject, HTML body, and text body. A non-null variables array with no mode selects explicit. automatic rejects a simultaneous non-null array; explicit requires a non-null array, including valid [], and preserves its exact order, duplicates, and string contents.
automatic, explicit Per-template strict variable-validation setting. Defaults to false for backward compatibility. When true, a send or render that is missing a variable marked required: true in variable_schema fails with 422 naming the variable. Missing optional variables never fail; their schema default (when set) is applied to the render.
Per-template HTML autoescaping setting. Defaults to false for backward compatibility. When true, the rendered html_body HTML-escapes each Liquid expression's output at the output boundary (after its filters run, before concatenation with literal template markup). Input values are never mutated and subject/text_body are never autoescaped. The boundary escape is idempotent: HTML entities already present in the output (e.g. from an explicit escape filter) are preserved, so an explicit escape/escape_once is never double-escaped, and markup introduced by any later filter in the chain is still escaped.
Structured variable requirements. Required variables cannot define defaults; invalid combinations return 422. This is independent of the legacy variables array. On render with strict_variables enabled: required variables must be supplied as non-empty values — absent, null, empty string, empty object {}, and empty array [] all fail with 422 naming the variable, while present values such as false and 0 pass (they are present, not empty). Optional variables fall back to their default when absent.
Show child attributes
Show child attributes
Response
Template created.
Show child attributes
Show child attributes
Was this page helpful?
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const EmailTemplate = await client.emailTemplates.create({
name: 'name',
});
console.log(EmailTemplate.data);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
email_template = client.email_templates.create(
name="name",
)
print(email_template.data)
package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
emailTemplate, err := client.EmailTemplates.New(
context.TODO(),
telnyx.EmailTemplateNewParams{
Name: "name",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", emailTemplate.Data)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.emailTemplates.EmailTemplateCreateParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
EmailTemplateCreateParams params = EmailTemplateCreateParams.builder()
.name("name")
.build();
var response = client.emailTemplates().create(params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
email_template = telnyx.email_templates.create(name: "name")
puts(email_template)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$email_template = $client->emailTemplates->create(
name: 'name',
);
var_dump($email_template);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx email-templates create \
--api-key 'My API Key' \
--name namecurl --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 }}"
}
'{
"data": {
"record_type": "email_template",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>",
"html_body": "<string>",
"text_body": "<string>",
"variables": [
"<string>"
],
"variables_mode": "automatic",
"strict_variables": true,
"autoescape": true,
"variable_schema": {},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"subject": "<string>"
}
}{
"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": [
{
"code": "10007",
"title": "Unexpected error",
"detail": "An unexpected error occured."
}
]
}{
"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."
}
]
}