Create a Message Template

POST

https://api.itniotech.com/wa/template/add

Used to create message templates, and then send template messages according to the templates
 
Request Parameters
Parameters Description Required Type
appId Application id Yes String
channelType Channel type: 0-WhatsApp, send 0 by default Yes Integer
templateName Template name: lowercase letters, numbers and underscores, 512 characters Yes String
type Template type: 0-AUTHENTICATION (authentication); 1-MARKETING (marketing); 2-UTILITY (transaction class) Yes Integer
language Template language: such as "zh_CN", see detailsCountry language enumeration definition, a template name can exist in multiple languages, only one language can be created at a time Yes String
components Template component No Object
header Header No Object
type Component type: HEADER, default HEADER Yes String
format Type of header: 0-TEXT, 1-IMAGE, 2-VIDEO, 3-DOCUMENT, 4-LOCATION Yes String
text Up to 60 characters, allowing 1 variable to be inserted. Required when type=HEADER, format=0 Yes String
example Header variable example. Required when there are variables in text Yes Object
header_text Example header text variable. Required when there are variables in header Yes Array
header_handle The handle of the file returned by calling the upload template sample file interface. Required when the header is a image/video/document. No Array
body Component type No Object
type Component type: BODY, default BODY Yes String
text Up to 1024 characters, allows inserting variables, limit up to 20 variables. Required when the template type is transaction-related and marketing No String
add_security_recommendation Add security advisories: true, false. Required when template type is authentication No Boolean
example Text variable example. Required when there are variables in text No Object
body_text Example of text variables in the body text, variables must be filled in the body text. Optional, consistent with the number of variables in text No Array
footer Component type No Object
type Component type: FOOTER, default FOOTER No String
text up to 60 characters. It must be passed When the template type isn't authentication No String
code_expiration_minutes The expiration time of the verification code, the identity verification template has this item, the value can be filled in the range of 1-90 No Integer
button Component type No Object
type Component type: BUTTONS, default BUTTONS. Required when template type is authentication No String
buttons button object No Object
type Button type: 1-URL, 2-UICK_REPLY, 3-OTP, 4-PHONE_NUMBER, 5-ONE_TAP Yes Integer
text The displayed name of the button, within 25 characters. (type is URL, QUICK_REPLY, PHONE_NUMBER required) Yes String
otp_type Verification code button type: copy_code (copy verification code), one_tap (one-click filling) Yes String
phone_number The phone number that will be dialed when the user taps the button, within 20 characters. (type is PHONE_NUMBER required) Yes String
url When an app user taps the button, the URL will be loaded in the device's default mobile web browser. Supports 1 variable, which should be appended to the end of the URL string, and the variable name needs to be set to {{1}}. 2,000 characters or less in length. (type is URL required) Yes String
example Example URL, 2,000 characters or less. (type is dynamic URL is required) Yes Array
autofill_text The name of the one-touch button. (type is ONE_TAP required) Yes String
package_name Android application package name. (type is ONE_TAP required) Yes String
signature_hash Apply signing key hash. (type is ONE_TAP required) Yes String
 
Request Sample
Request URL:
    https://api.itniotech.com/wa/template/add
Request Method:
    POST
Request Headers:
    Content-Type: application/json;charset=UTF-8
    Sign: 05d7a50893e22a5c4bb3216ae3396c7c
    Timestamp: 1690286812882
    Api-Key: 7Wqzu5rm

//Create a marketing template with a header of text, with buttons for phone and website, and a variable for the main text (template type can be matched freely)
Request Body:
{
    "appId": "yYgJ5EVD",
    "channelType": 0,
    "templateName": "dd_template",
    "type": 1,
    "language": "zh_CN",
    "components":
    {
        "header":{
            "type": "HEADER",
            "format": 0,
            "text": "OTP is currently in {{#}} activity",
            "example": {
                "header_text": ["Discounts"]
            }
        },
        "body":{
            "type": "BODY",
            "text": "The company is newly opened, and {{#}} activities are in full swing...",
            "example":{
                "body_text": [
                    ["Discounts"]
                ]
            }
        },
        "footer": {
            "type": "FOOTER",
            "text": "ITNIOTECH"
        }
    }
}

//Create Template: Identity Authentication Class
{
    "appId": "yYgJ5EVD",
    "channelType": 0,
    "templateName": "skyline_template_tt",
    "type": 0,
    "language": "zh_CN",
    "components": {
        "body": {
            "type": "BODY",
            "add_security_recommendation": true
        },
        "button": {
            "type": "BUTTONS",
            "buttons": [{
                "otp_type": "COPY_CODE",
                "text": "3232",
                "type": 3
            }]
        },
        "footer": {
            "type": "FOOTER",
            "code_expiration_minutes": 10
        }
    }
}

//Transaction type without request header
{
    "appId": "DHhgCjMX",
    "channelType": 0,
    "templateName": "sjhdd_template_jy_1",
    "type": 2,
    "language": "cs",
    "components": {
        "body": {
            "type": "BODY",
            "text": "You have successfully checked in! Below is the boarding pass for this flight{{#}} {{#}}k {{#}} whe de ds d fd htttt ",
            "example": {
                "body_text": [
                    ["you","and","haha"]
                ]
            }
        },
        "footer": {
            "type": "FOOTER",
            "text": "You have successfully checked in!"
        }
    }
}
 
Response Parameters
Parameters Description Type
status Status code, 0 is successful, other failures refer to the interface response code String
reason Reason for failure String
data Send result Object
templateId Template id String
templateName Template name String
type Template type: 0-AUTHENTICATION (authentication); 1-MARKETING (marketing); 2-UTILITY (transaction class) String
languageCode Template language, see Country Enumeration for details String
status Template status: PENDING (under review), REJECTED (not passed the review), APPROVED (passed the review), DELETED (deleted), DISABLED (disabled),PENDING_DELETION (pending deletion), IN_APPEAL (appeal filed), PAUSED (temporarily suspended), LIMIT_EXCEEDED (limit exceeded), FLAGGED (planned to be disabled), REINSTATED (reinstated) String
 
Response Status Code
status Description
0 success
-1 Authentication error
-2 Incorrect template status
-4 Timestamp expires
-5 System exception !
-6 Restricted IP access
-7 json parse exception, plase check you param's type and json format
-8 Abnormal parameter verification
-10 Application does not exist
-11 The application name already exists
-12 Network exception or parameter error
-14 Account not authenticated
-16 the same name template is deleted and cannot be used again within one month
-18 The fileId cannot be blank
-19 The fileId cannot be blank
-21 The header message is too long.
-23 Button type cannot be empty
-24 The quantity of buttons are too many
-32 The current templateName and language already exist
-33 The elementName format is incorrect.
-34 Template content cannot have continuous variables
-37 Error creating template
-38 It is failed to delete the template,current template was not found.
-40 Example file too large
-74 The languageCode format err
-75 The template type does not match the existing type.
-76 Please enter the correct type
-77 Please enter the correct format PhoneNumber and areaCode
-78 Please enter the correct language
-82 The bodyExample is too long
-83 Please enter the correct format params
-84 The text cannot be empty
-86 Template body type cannot be null
-87 Template footer type cannot be null
-88 Template footer text is too long
-89 Template component cannot be null
-90 The header cannot have continuous variables
-91 The number of variables in the header text does not match the number of examples. or The number of variables in the header text can not greater than one
-92 The text length cannot be greater than 25
-99 The channelType error !
-100 header format cannot be empty case type is text
-101 Please enter the correct format value
-102 Please enter the correct of button type, only OTP is supported(type:3)
-103 Body text not be null when type not 0 (AUTHENTICATION)
-104 The body add security recommendation param error
-105 Template footer text length cannot more than 60
-106 code_expiration_minutes must be lower or equal to 90
-107 This app have not app alias!
-108 Button otp_type cannot be empty
-109 when template type is 0 (AUTHENTICATION), buttons cannot be empty
 

language

Java

PHP

REQUEST

package com.itniotech.api.demo.im;

import cn.hutool.core.map.MapUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

private static void createTemplate() {
    final String baseUrl = "https://api.itniotech.com/wa/";
    final String apiKey = "your api key";
    final String apiPwd = "your api secret";
    final String appId = "your appid";

    final String templateName = "template name"; //the template name
    final String language = "language code"; // the template support language
    final int channelType = 0; //channelType: 0-WhatsApp, default is 0
    final int type = 1;

    final String url = baseUrl.concat("template/add");

    HttpRequest request = HttpRequest.post(url);

    // currentTime
    final String datetime = String.valueOf(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().getEpochSecond());

    final String sign = SecureUtil.md5(apiKey.concat(apiPwd).concat(datetime));
    request.header(Header.CONNECTION, "Keep-Alive")
            .header(Header.CONTENT_TYPE, "application/json;charset=UTF-8")
            .header("Sign", sign)
            .header("Timestamp", datetime)
            .header("Api-Key", apiKey);

    String headerJson = "{"type":"HEADER","format":0,"text":"OTP is currently in {{#}} activity","example":{"header_text":["Discounts"]}}";
    String bodyValJson = "{"type":"BODY","text":"The company is newly opened, and {{#}} activities are in full swing","example":{"body_text":[["Discounts"]]}}";
    String footerJson = "{"type":"FOOTER","text":"ITNIOTECH"}";


    Map componentsMap = MapUtil.builder("header", JSONUtil.parseObj(headerJson))
                                                .put("body", JSONUtil.parseObj(bodyValJson))
                                                .put("footer", JSONUtil.parseObj(footerJson))
                                                .build();

    String body = JSONUtil.createObj()
            .set("appId", appId)
            .set("channelType", channelType)
            .set("templateName", templateName)
            .set("type", type)
            .set("components", componentsMap)
            .set("language", language)
            .toString();

    HttpResponse response = request.body(body).execute();
    if (response.isOk()) {
        String result = response.body();
        System.out.println(result);
    }
}        
                

REQUEST

//创建消息模板
header('content-type:text/html;charset=utf8');

$apiKey = "your api key";
$apiSecret = "your api secret";
$appId = "your appid";
$timeStamp = time();
$sign = md5($apiKey.$apiSecret.$timeStamp);
$headers = array('Content-Type:application/json;charset=UTF-8',"Sign:$sign","Timestamp:$timeStamp","Api-Key:$apiKey");

$url = "https://api.itniotech.com/wa/template/add";

$dataArr["appId"] = $appId;
$dataArr["channelType"] = 0;
$dataArr["templateName"] = "template name";
$dataArr["type"] = 1;
$dataArr["language"] = "language code";

$headerArray = array(
    array(
        "type" => "HEADER",
        "format" => 0,
        "text" => "OTP is currently in {{#}} activity",
        "example" => array(
            "header_text" => "Discounts"
        )
    )
);
$bodyArray = array(
    array(
        "type" => "BODY",
        "text" => "The company is newly opened, and {{#}} activities are in full swing",
        "example" => array(
            "body_text" => "Discounts"
        )
    )
);
$footerArray = array(
    array(
        "type" => "FOOTER",
        "text" => "ITNIOTECH"
    )
);
$dataArr["components"] = array(
    'header' => $headerArray,
    'body' => $bodyArray,
    'footer' => $footerArray
);

$data = json_encode($dataArr);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 600);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_POSTFIELDS , $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

$output = curl_exec($ch);
curl_close($ch);
var_dump($output);        
                
 

RESPONSEEXAMPLE

{
    "status": "0",
    "reason": "success",
    "data": {
    "templateId": "0bd9ea48738d4d0db667b1e1f50020a9",
        "templateName": "itnio_template_xk_test",
        "type": 1,
        "languageCode": "en",
        "status": "APPROVED"
    }
}