×

Use the create templates API to create & submit templates to WhatsApp for approval. The API supports both single and bulk create.

POST

https://<api_key>:<api_token><subdomain>/v2/accounts/<your_sid>/templates

  • Replace <your_api_key> and <your_api_token> with the API key and token created by you.
  • Replace <your_sid> with your “Account sid”
  • Replace <subdomain> with the region of your account
    1. <subdomain> of Singapore cluster is @api.exotel.com
    2. <subdomain> of Mumbai cluster is @api.in.exotel.com

<your_api_key> , <your_api_token> and <your_sid> are available in the API settings page of your Exotel Dashboard

Listed below are the parameters for the POST API.

HTTPRequestObject

Parameter Name

Type

Mandatory/ Optional

Value/ Description

waba_id

String

Mandatory

Waba ID

 

Parameter Name

Type

Mandatory/ Optional

Value/ Description

custom_data

String

Optional

If the client wants to send any custom data at the request level. This will be passed back to the customer in the callback.

whatsapp

ChannelObject

Optional

Information related to the messages to be sent out on whatsapp

ChannelObject

Parameter

Type

Mandatory

Notes

custom_data

String

Optional

If the client wants to send any custom data at the channel level. This will be passed back to the customer in the callback.

messages

[]TemplateObject

Mandatory

Array of messages to be sent out

TemplateObject

Parameter Name

Type

Mandatory

Value/ Description

custom_data

String

Optional

If the client wants to send any custom data at the message level. This will be passed back to the customer in the callback.

template

WhatsappTemplateObject

Mandatory

Respective channel specific template body

WhatsappTemplateObject

Parameter Name

Type

Mandatory/ Optional

Value/ Description

category

String

Mandatory

Category of the template

name

String

Mandatory

Name of the template

language

String

Mandatory

Language of the template

components

[]ComponentObject

Mandatory

Components of the template

ComponentObject

Parameter Name

Type

Mandatory/ Optional

Value/ Description

type

String

Mandatory

Type of the component

text

String

Mandatory/Optional

Mandatory in case of type FOOTER/BODY/URL and TEXT HEADER

format

String

Mandatory/Optional

Mandatory in case of type HEADER

buttons

[]ButtonObject

Mandatory/Optional

Mandatory in case of type BUTTONS

url

String

Mandatory/Optional

Mandatory in case of type URL

example

ExampleObject

Mandatory/Optional

Mandatory in case of dynamic variables or media header

example

[]String

Mandatory/Optional

Mandatory in case of dynamic variables in type URL

 
ButtonObject

Parameter Name

Type

Mandatory/ Optional

Values/ Description

type

String

Optional

Fallback value of datetime

text

Integer

Optional

Day of Week of datetime

phone_number

Integer

Optional

Day of month of datetime

ExampleObject

Parameter Name

Type

Mandatory

Value/ Description

body_text

[][]String

Mandatory

Type of the parameter

header_text

[]String

Optional

Text for the parameter

header_handle

[]String

Optional

Caption for the parameter

 

curl --location --request POST 'https://<api_key>:<api_token><subdomain>/v2/accounts/<your_sid>/templates?waba_id=<Your WABA ID>' \

--header 'Content-Type: application/json' \

--data-raw '{

"whatsapp": {

"templates": [

{

"template": {

"category": "TRANSACTIONAL",

"components": [

{

"type": "HEADER",

"format": "TEXT",

"text": "Greetings from Exotel {{1}}",

"example": {

"header_text": [

"John Doe"

]

}

},

{

"type": "BODY",

"text": "Hi {{1}}, your one time password is {{2}}.",

"example": {

"body_text": [

[

"John",

"1234"

]

]

}

},

{

"type": "FOOTER",

"text": "Thanks"

}

],

"name": "test_template4605",

"language": "en"

}

},







}

}'
var https = require('follow-redirects').https;

var fs = require('fs');

var options = {

'method': 'POST',

'hostname': '<Sub domain>',

'path': '/v2/accounts/<Your SID>/templates?waba_id=<Your WABA ID',

'headers': {

'Content-Type': 'application/json'

},

'maxRedirects': 20

};

var req = https.request(options, function (res) {

varchunks= [];

res.on("data", function (chunk) {

chunks.push(chunk);

});

res.on("end", function (chunk) {

varbody=Buffer.concat(chunks);

console.log(body.toString());

});

res.on("error", function (error) {

console.error(error);

});

});

var postData = "{\n \"whatsapp\": {\n \"templates\": [\n {\n \"template\": {\n \"category\": \"TRANSACTIONAL\",\n \"components\": [\n {\n \"type\": \"HEADER\",\n \"format\": \"TEXT\",\n \"text\": \"Greetings from Exotel {{1}}\",\n \"example\": {\n \"header_text\": [\n \"John Doe\"\n ]\n }\n },\n {\n \"type\": \"BODY\",\n \"text\": \"Hi {{1}}, your one time password is {{2}}.\",\n \"example\": {\n \"body_text\": [\n [\n \"John\",\n \"1234\"\n ]\n ]\n }\n },\n {\n \"type\": \"FOOTER\",\n \"text\": \"Thanks\"\n }\n ],\n \"name\": \"test_template4605\",\n \"language\": \"en\"\n }\n },\n \n \n }\n}";

HTTP Response

  • On success, the HTTP response status code will be 200.
{

"request_id": "72f3624613a84932823f838fcecf7389",

"method": "POST",

"http_code": 200,

"metadata": {

"failed": 0,

"total": 1,

"success": 1

},

"response": {

"whatsapp": {

"templates": [

{

"code": 200,

"error_data": null,

"status": "success",

"data": {

"id": "903269234317278"

}

}

]

}

}

}

HTTPResponseObject

Parameter Name

Type

Mandatory/ Optional

Value/ Description

request_id

String

Mandatory

ID of the request

method

String

Mandatory

HTTP Request Method

http_code

Integer

Mandatory

HTTP Code of the request

metadata

MetadataObject

Mandatory

Metadata pertaining to the request

response

ResponseObject

Mandatory

Response for the request

MetadataObject

Parameter Name

Type

Mandatory/ Optional

Value/ Description

total

Integer

Mandatory

Total number of the messages in the request

success

Integer

Mandatory

Number of messages successfully accepted

failed

Integer

Mandatory

Number of messages that couldn’t be accepted

ResponseObject

Parameter Name

Type

Mandatory/ Optional

Value/ Description

whatsapp

ChannelResponseObject

Optional

Channel Response for Whatsapp

ChannelResponseObject

Parameter Name

Type

Mandatory/ Optional

Description

templates

[]CreateTemplateResponseObject

Optional

Message Response

CreateTemplateResponseObject

Parameter Name

Type

Mandatory/ Optional

Value/ Description

code

Integer

Mandatory

Response code for the message

error_data

ErrorResponseObject

Optional

Error related to message

status

String

Mandatory

Status of the message

data

TemplateResponseObject

Optional

Data for the message

ErrorResponseObject

Parameter Name

Type

Mandatory/ Optional

Value/ Description

code

Numeric

Mandatory

Numeric error code

message

String

Mandatory

Brief explanation of error

description

String

Mandatory

Detailed explanation of error

TemplateResponseObject

Parameter Name

Type

Mandatory/ Optional

Value/ Description

id

String

Mandatory

id (Unique identifier) of the template

custom_data

String

Mandatory

Custom data passed in the request