CreateTemplate#
The method is intended to create the new template.
Request#
To create the template, you need to execute a request to:
POST {{apiUrl}}/waInstance{{idInstance}}/createTemplate/{{apiTokenInstance}}
For idInstance
, apiTokenInstance
and apiUrl
request parameters, refer to Before you start section.
Request parameters#
Parameter | Type | Mandatory | Description |
---|---|---|---|
elementName | string | Yes | Template name. The element name is unique within the WABAs namespace. Parameter can only contain small letters, numbers and underscores. |
languageCode | string | Yes | Language code for the template. See all language codes in the table below |
category | string | Yes | The category of your template. Possible values : AUTHENTICATION , MARKETING and UTILITY . If you send a different value, you will receive an error message: Invalid category provided, kindly use category from these options AUTHENTICATION,MARKETING,UTILITY . |
templateType | string | Yes | Template type: TEXT , IMAGE , VIDEO , DOCUMENT . |
vertical | string | Yes | Brief description of the template for passing Meta verification. Character limit: 180 |
content | string | Yes* | Template body. Character limit is 550. * For the AUTHENTICATION category template, the field is optional. * If the field is present, its format must be: *{{1}}* is your verification code . * If the field is missing, the value *{{1}}* is your verification code will be automatically applied. |
header | string | No | Template header. Applicable for template type = Text. Character limit: 60 . |
exampleHeader | string | No * | Example of template title text. Not applicable for template type: CATALOG . Use only lowercase letters in exampleHeader , as using uppercase letters results in an error. * When using the header field in a request, the field is mandatory |
footer | string | No | Template footer. Character limit: 60 . |
buttons | array | No* | Message buttons * The AUTHENTICATION category template must have at least one button of the OTP type. Request parameter example: "buttons": "[{'type':'OTP','otp_type':'COPY_CODE'}]" |
example | string | Yes* | Your text with substituted examples of variable values instead of parameters in the SendTemplates method * For the AUTHENTICATION category template, the field is optional. * If the field is present, its format must be: *1234* is your verification code . * If the field is missing, the value *1234* is your verification code will be automatically applied. |
enableSample | boolean | No | An option that is required to create all types of templates. |
allowTemplateCategoryChange | boolean | No | Boolean value. If TRUE , WhatsApp will automatically update the template category according to the template content. The default value is FALSE . If the category is updated, you can view the old category via the GetTemplates method. |
addSecurityRecommendation | boolean | No | Optionally, a disclaimer is added to the content for the AUTHENTICATION category. For security purposes, do not share this code. |
codeExpirationMinutes | number | No | Optionally, the following text is added to the footer for the AUTHENTICATION category: This code will expire in <NUM_MINUTES> minutes. Codes must be valid for between 1 and 90 minutes. |
Language codes
Language | Code |
---|---|
Afrikaans | af |
Albanian | sq |
Arabic | ar |
Azerbaijani | az |
Bengali | bn |
Bulgarian | bg |
Catalan | ca |
Chinese (CHN) | zh_CN |
Chinese (HKG) | zh_HK |
Chinese (TAI) | zh_TW |
Croatian | hr |
Czech | cs |
Danish | da |
Dutch | nl |
English | en |
English (UK) | en_GB |
English (US) | en_US |
Estonian | et |
Filipino | fil |
Finnish | fi |
French | fr |
Georgian | ka |
German | de |
Greek | el |
Gujarati | gu |
Hausa | ha |
Hebrew | he |
Hindi | hi |
Hungarian | hu |
Indonesian | id |
Irish | ga |
Italian | it |
Japanese | ja |
Kannada | kn |
Kazakh | kk |
Kinyarwanda | rw_RW |
Korean | ko |
Kyrgyz (Kyrgyzstan) | ky_KG |
Lao | lo |
Latvian | lv |
Lithuanian | lt |
Macedonian | mk |
Malay | ms |
Malayalam | ml |
Marathi | mr |
Norwegian | nb |
Persian | fa |
Polish | pl |
Portuguese (BR) | pt_BR |
Portuguese (POR) | pt_PT |
Punjabi | pa |
Romanian | ro |
Russian | ru |
Serbian | sr |
Slovak | sk |
Slovenian | sl |
Spanish | es |
Spanish (ARG) | es_AR |
Spanish (SPA) | es_ES |
Spanish (MEX) | es_MX |
Swahili | sw |
Swedish | sv |
Tamil | ta |
Telugu | te |
Thai | th |
Turkish | tr |
Ukrainian | uk |
Urdu | ur |
Uzbek | uz |
Vietnamese | vi |
Zulu | zu |
buttons
array parameters#
Parameter | Type | Required | Description |
---|---|---|---|
type | string | Yes | The type of button to send. Possible types: - QUICK_REPLY - allows you to send a quick response by pressing a button with a prepared text. - URL - allows you to open a link by pressing a button. - PHONE_NUMBER - allows you to start a call by pressing a button. |
text | string | Yes | The text on the button. For the QUICK_REPLY and URL types, the maximum length is 25 characters. For the PHONE_NUMBER type, the maximum length is 20 characters. |
phone_number | string | No | Field for a button of the PHONE_NUMBER type. The phone number that will be called when the button is clicked. |
url | string | No | Field for a button of the URL type. The link that will be accessed when the button is clicked. |
Request body example#
Example body of a request to create a template with MARKETING
category
{
"elementName": "ticket_check_url_4245343",
"languageCode": "en_US",
"category": "MARKETING",
"templateType": "TEXT",
"vertical": "TEXT",
"content": "your ticket has been confirmed for {{1}} persons on date {{2}}.",
"header": "This is the header",
"exampleHeader": "This is the header",
"footer": "This is the footer",
"buttons": "[{'type':'PHONE_NUMBER','text':'Call Us','phone_number':'919872329959'},{'type':'URL','text':'Book A Demo','url':'https://GREEN-API.io/abc','example':['https://GREEN-API.io/abc'], {'type':'QUICK_REPLY','text':'Demo Button'}]",
"example": "your ticket has been confirmed for 4 persons on date 2020-05-04.",
"enableSample": true,
"allowTemplateCategoryChange": false
}
Example body of a request to create a template with AUTHENTICATION
category
{
"elementName": "ticket_check_url_4245343",
"languageCode": "en_US",
"category": "AUTHENTICATION",
"templateType": "TEXT",
"vertical": "TEXT",
"content": "*{{1}}* is your verification code.",
"buttons": "buttons": "[{'type':'OTP','otp_type':'COPY_CODE'}]",
"example": "*1234* is your verification code.",
"enableSample": true,
"allowTemplateCategoryChange": false
}
Response#
Response parameters#
Parameter | Type | Description |
---|---|---|
template | object | Created template object |
Response template parameters#
Parameter | Type | Description |
---|---|---|
buttonSupported | string | Types of buttons used in the template. |
category | string | Template category. |
containerMeta | string | A fully formed request sent to Meta for verification. |
createdOn | number | Template creation timestamp (in milliseconds) |
data | string | Data field from the template, text representation of the template. |
elementName | string | The template's name is specified in the body of the CreateTemplate request. |
languageCode | string | The template language is from the body of the CreateTemplate request. |
languagePolicy | string | Service field for defining the language for Meta. |
meta | string | The field containing a sample template. |
modifiedOn | number | Template editing timestamp (in milliseconds). Equal to createdOn when creating the template. |
namespace | string | GREEN-API Account ID. |
priority | number | The template priority given by Meta. |
quality | string | A service field for template evaluation by Meta. |
retry | number | The number of times a template is resubmitted for verification in Meta. |
stage | string | Service field of the Meta request processing stage. |
status | string | Meta verification status for the template. Can have the following values: PENDING (under consideration), APPROVED (the template has been verified and can be sent), REJECTED (the template has not been verified, Meta considers the template suspicious), FAILED (the template has not been verified, there is an error in the request body. The reason is specified in the additional reason field), PAUSED (the template has been suspended). |
templateType | string | Template type |
vertical | string | Brief description of the template for passing Meta verification. |
templateId | string | ID of the created template for interaction with it. |
Response body example#
Status code success: 200 OK.
{
"template": {
"appId": "****f7-***33-4**d-8f***-c***d*****",
"category": "MARKETING",
"createdOn": 1652768999707,
"data": "Hi, you Welcome to Header.\nHi, {{1}}. This is the template for header testing.\nHi, Welcome to Footer. | [call,917676767676] | [ur,https://www.fb.com]",
"elementName": "test_template12332",
"id": "f****a-f****-4**2-8***4-dc****ea",
"languageCode": "en",
"languagePolicy": "deterministic",
"master": true,
"meta": "{\"example\":\"Hi, [john]. This is the template for header testing.\"}",
"modifiedOn": 1652768999707,
"namespace": "e***3_e5**_**de_***3_20****1b",
"status": "PENDING",
"templateType": "TEXT",
"vertical": "Header",
"allowTemplateCategoryChange": "false"
}
}
CreateTemplate errors#
For a list of errors common to all methods, refer to Common errors section.
Request examples#
curl --location '{{apiUrl}}/waInstance{{idInstance}}/createTemplate/{{apiTokenInstance}}' \
--header 'Content-Type: application/json' \
--data 'elementName=ticket_check_url_4245343' \
--data 'languageCode=en_US' \
--data 'category=MARKETING' \
--data 'templateType=TEXT' \
--data 'vertical=TEXT' \
--data 'content=your ticket has been confirmed for {{1}} persons on date {{2}}.' \
--data 'header=This is the header' \
--data 'exampleHeader=This is the header' \
--data 'footer=This is the footer' \
--data 'buttons=[{'type':'PHONE_NUMBER','text':'Call Us','phone_number':'919872329959'},{'type':'URL','text':'Book A Demo','url':'https://GREEN-API.io/{{1}}','example':['https://GREEN-API.io/abc']}, {'type':'QUICK_REPLY','text':'Demo Button'}]' \
--data 'example=your ticket has been confirmed for 4 persons on date 2020-05-04.' \
--data 'enableSample=true' \
--data 'allowTemplateCategoryChange=false'