Create a Whatsapp message template
POST
/
whatsapp
/
message_templates
JavaScript
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const template = await client.whatsapp.templates.create({
category: 'MARKETING',
components: [{ format: 'TEXT', type: 'HEADER' }],
language: 'language',
name: 'name',
waba_id: 'waba_id',
});
console.log(template.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
)
template = client.whatsapp.templates.create(
category="MARKETING",
components=[{
"format": "TEXT",
"type": "HEADER",
}],
language="language",
name="name",
waba_id="waba_id",
)
print(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"),
)
template, err := client.Whatsapp.Templates.New(context.TODO(), telnyx.WhatsappTemplateNewParams{
Category: telnyx.WhatsappTemplateNewParamsCategoryMarketing,
Components: []telnyx.WhatsappTemplateNewParamsComponentUnion{{
OfHeader: &telnyx.WhatsappTemplateNewParamsComponentHeader{
Format: "TEXT",
},
}},
Language: "language",
Name: "name",
WabaID: "waba_id",
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", template.Data)
}package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.whatsapp.templates.TemplateCreateParams;
import com.telnyx.sdk.models.whatsapp.templates.TemplateCreateResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
TemplateCreateParams params = TemplateCreateParams.builder()
.category(TemplateCreateParams.Category.MARKETING)
.addHeaderComponent(TemplateCreateParams.Component.Header.Format.TEXT)
.language("language")
.name("name")
.wabaId("waba_id")
.build();
TemplateCreateResponse template = client.whatsapp().templates().create(params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
template = telnyx.whatsapp.templates.create(
category: :MARKETING,
components: [{format: :TEXT, type: :HEADER}],
language: "language",
name: "name",
waba_id: "waba_id"
)
puts(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 {
$template = $client->whatsapp->templates->create(
category: 'MARKETING',
components: [
[
'format' => 'TEXT',
'type' => 'HEADER',
'example' => ['headerHandle' => ['string'], 'headerText' => ['string']],
'text' => 'text',
],
],
language: 'language',
name: 'name',
wabaID: 'waba_id',
);
var_dump($template);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx whatsapp:templates create \
--api-key 'My API Key' \
--category MARKETING \
--component '{format: TEXT, type: HEADER}' \
--language language \
--name name \
--waba-id waba_idcurl --request POST \
--url https://api.telnyx.com/v2/whatsapp/message_templates \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"waba_id": "<string>",
"name": "<string>",
"language": "<string>",
"components": [
{
"type": "HEADER",
"text": "<string>",
"example": {
"header_text": [
"<string>"
],
"header_handle": [
"<string>"
]
}
}
]
}
'{
"data": {
"id": "<string>",
"record_type": "whatsapp_message_template",
"template_id": "<string>",
"name": "<string>",
"language": "<string>",
"status": "<string>",
"rejection_reason": "<string>",
"components": [
{}
],
"whatsapp_business_account": {
"id": "<string>"
},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}
}{
"errors": [
{
"code": "<string>",
"title": "<string>",
"detail": "<string>",
"source": {
"pointer": "<string>",
"parameter": "<string>"
},
"meta": {}
}
]
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/json
The WhatsApp Business Account ID.
Template name. Lowercase letters, numbers, and underscores only.
Template category: AUTHENTICATION, UTILITY, or MARKETING.
Available options:
MARKETING, UTILITY, AUTHENTICATION Template language code (e.g. en_US, es, pt_BR).
Template components defining message structure. Passed through to Meta Graph API. Templates with variables must include example values. Supports HEADER, BODY, FOOTER, BUTTONS, CAROUSEL and any future Meta component types.
A template component. Additional Meta component types not listed here are also accepted.
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
Show child attributes
Show child attributes
Response
Template created
Show child attributes
Show child attributes
Was this page helpful?
⌘I
JavaScript
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const template = await client.whatsapp.templates.create({
category: 'MARKETING',
components: [{ format: 'TEXT', type: 'HEADER' }],
language: 'language',
name: 'name',
waba_id: 'waba_id',
});
console.log(template.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
)
template = client.whatsapp.templates.create(
category="MARKETING",
components=[{
"format": "TEXT",
"type": "HEADER",
}],
language="language",
name="name",
waba_id="waba_id",
)
print(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"),
)
template, err := client.Whatsapp.Templates.New(context.TODO(), telnyx.WhatsappTemplateNewParams{
Category: telnyx.WhatsappTemplateNewParamsCategoryMarketing,
Components: []telnyx.WhatsappTemplateNewParamsComponentUnion{{
OfHeader: &telnyx.WhatsappTemplateNewParamsComponentHeader{
Format: "TEXT",
},
}},
Language: "language",
Name: "name",
WabaID: "waba_id",
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", template.Data)
}package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.whatsapp.templates.TemplateCreateParams;
import com.telnyx.sdk.models.whatsapp.templates.TemplateCreateResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
TemplateCreateParams params = TemplateCreateParams.builder()
.category(TemplateCreateParams.Category.MARKETING)
.addHeaderComponent(TemplateCreateParams.Component.Header.Format.TEXT)
.language("language")
.name("name")
.wabaId("waba_id")
.build();
TemplateCreateResponse template = client.whatsapp().templates().create(params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
template = telnyx.whatsapp.templates.create(
category: :MARKETING,
components: [{format: :TEXT, type: :HEADER}],
language: "language",
name: "name",
waba_id: "waba_id"
)
puts(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 {
$template = $client->whatsapp->templates->create(
category: 'MARKETING',
components: [
[
'format' => 'TEXT',
'type' => 'HEADER',
'example' => ['headerHandle' => ['string'], 'headerText' => ['string']],
'text' => 'text',
],
],
language: 'language',
name: 'name',
wabaID: 'waba_id',
);
var_dump($template);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx whatsapp:templates create \
--api-key 'My API Key' \
--category MARKETING \
--component '{format: TEXT, type: HEADER}' \
--language language \
--name name \
--waba-id waba_idcurl --request POST \
--url https://api.telnyx.com/v2/whatsapp/message_templates \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"waba_id": "<string>",
"name": "<string>",
"language": "<string>",
"components": [
{
"type": "HEADER",
"text": "<string>",
"example": {
"header_text": [
"<string>"
],
"header_handle": [
"<string>"
]
}
}
]
}
'{
"data": {
"id": "<string>",
"record_type": "whatsapp_message_template",
"template_id": "<string>",
"name": "<string>",
"language": "<string>",
"status": "<string>",
"rejection_reason": "<string>",
"components": [
{}
],
"whatsapp_business_account": {
"id": "<string>"
},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}
}{
"errors": [
{
"code": "<string>",
"title": "<string>",
"detail": "<string>",
"source": {
"pointer": "<string>",
"parameter": "<string>"
},
"meta": {}
}
]
}