Template API Interface
Create Template
Endpoint
POST https://otp.api.engagelab.cc/v1/template-configs
Authentication
Use HTTP Basic Authentication by adding Authorization in the HTTP Header:
Authorization: Basic ${base64_auth_string}
The base64_auth_string is generated as follows: base64(dev_key:dev_secret)
Request Example
Request Header
POST /v1/messages HTTP/1.1
Content-Type: application/json
Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0
Request Body
{
"template_id": "test-template-1", // Custom template ID, unique within the application
"description": "Test Template 1", // Description of the template
"send_channel_strategy": "whatsapp|sms", // Template delivery strategy, supports four types: whatsapp/sms/voice/email. Use | to indicate fallback strategy
"brand_name": "Brand Name", // Brand name, used in signature for some countries/regions in template content (e.g., required for SMS channels in certain countries/regions)
"verify_code_config": { // Verification code configuration, required when the template includes verification code type
"verify_code_type": 1, // Verification code type, range [1,7]
"verify_code_len": 6, // Verification code length, range [4,10]
"verify_code_ttl": 1 // Verification code validity period, range [1,10]. Note: When the strategy includes whatsapp, the value can only be 1, 5, or 10
},
"whatsapp_config": { // WhatsApp strategy configuration, effective when delivery strategy includes WhatsApp
"template_type": 1, // WhatsApp template type, currently only supports default template, fixed value 1
"template_default_config": { // WhatsApp default template configuration, effective for default template type
"contain_security": false, // Whether to include security reminders
"contain_expire": false // Whether to include expiration content
}
},
"sms_config": { // SMS strategy configuration, effective when delivery strategy includes SMS
"template_type": 2, // SMS template type, values: 1-Default Template/2-Custom Template
"template_default_config": { // SMS default template configuration, effective for default template type
"contain_security": false, // Whether to include security reminders
"contain_expire": false // Whether to include expiration content
},
"template_custom_config": { // SMS custom template configuration, effective for custom template type
"custom_sub_type": "authentication", // Custom template type, values: authentication-Verification Code/marketing-Marketing/utility-Notification
"custom_content": "xxx", // Custom template content. Note: For authentication type, must include {{code}} variable
"custom_country_codes": "HK,PH" // Target countries/regions for custom template, used as reference during template review. Fill in as needed, otherwise may affect delivery
}
},
"voice_config": { // Voice strategy configuration, effective when delivery strategy includes Voice
"template_type": 1, // Voice template type, currently only supports default template, fixed value 1
"template_default_config": { // Voice default template configuration, effective for default template type
"contain_security": false, // Whether to include security reminders
"contain_expire": false // Whether to include expiration content
}
},
"email_config": { // Email strategy configuration, effective when delivery strategy includes Email
"template_name": "Email Template Name", // Email template name
"template_custom_configs": [{ // Email custom template configuration, note this is an array of objects, mainly distinguished by language
"language": "default", // Language, default is the default. Template content can be matched based on the language parameter during delivery
"pre_from_name": "test", // Preset sender name
"pre_from_mail": "test@test.com", // Preset sender email
"pre_subject": "test", // Preset email subject
"template_content": "Preset email template content, required. Custom variables like {{self}}, verification code is {{code}}", // Email content, supports HTML. Variables must be enclosed in double curly braces {{}}
"pre_param_map": { // Default values for variables in email content. If variable values are not specified during delivery, these default values will replace the variables. Declared as key-value pairs, values must be strings
"self": "This is the preset value for the self variable"
}
}]
},
"pwa_config": { // PWA-related configuration, optional
"pwa_platform": "xx", // PWA platform used. For specific values, contact technical support
"pwa_code": "xx" // Code in the PWA platform used
}
}
Request Parameters
A request object is expressed in JSON format, so the request header must include Content-Type: application/json.
Parameter | Type | Option | Description |
---|---|---|---|
template_id | String | Required | Custom template ID, unique, limited to 128 characters |
description | String | Optional | Template description, limited to 255 characters |
send_channel_strategy | String | Required | Template strategy. Single channel values: whatsapp/sms/email/voice. Multi-channel use |
brand_name | String | Optional | Brand signature, replaces brand signature variable in some template styles with brand signature. Length limited to 2-10 characters |
verify_code_config | Object | Conditionally Required | Verification code configuration, required when the template includes verification code type |
verify_code_config.verify_code_type | Integer | Required | Verification code type, range [1,7]. 1-Numeric/2-Lowercase letters/4-Uppercase letters. Can be combined (e.g., 3 means numeric + lowercase letters) |
verify_code_config.verify_code_len | Integer | Required | Verification code length, range [4,10] |
verify_code_config.verify_code_ttl | Integer | Required | Verification code validity period, in minutes, range [1,10]. When the strategy includes WhatsApp, can only be 1, 5, or 10 |
whatsapp_config | Object | Conditionally Required | WhatsApp strategy configuration, required when delivery strategy includes WhatsApp |
whatsapp_config.template_type | Integer | Required | WhatsApp template type, currently only supports default template, fixed value 1 |
whatsapp_config.template_default_config | Object | Conditionally Required | WhatsApp default template configuration, required for default template type |
sms_config | Object | Conditionally Required | SMS strategy configuration, required when delivery strategy includes SMS |
sms_config.template_type | Integer | Required | SMS template type, 1-Default Template/2-Custom Template |
sms_config.template_default_config | Object | Conditionally Required | SMS default template configuration, required for default template type |
sms_config.template_custom_config | Object | Conditionally Required | SMS custom template configuration, required for custom template type |
sms_config.template_custom_config.custom_sub_type | String | Required | Custom template type, authentication-Verification Code/marketing-Marketing/utility-Notification |
sms_config.template_custom_config.custom_content | String | Required | Custom template content. For authentication type, must include {{code}} variable |
sms_config.template_custom_config.custom_country_codes | String | Optional | Target country/region codes, comma-separated, used as reference during template review |
voice_config | Object | Conditionally Required | Voice strategy configuration, required when delivery strategy includes Voice |
voice_config.template_type | Integer | Required | Voice template type, currently only supports default template, fixed value 1 |
voice_config.template_default_config | Object | Conditionally Required | Voice default template configuration, required for default template type |
email_config | Object | Conditionally Required | Email strategy configuration, required when delivery strategy includes Email |
email_config.template_name | String | Required | Email template name |
email_config.template_custom_configs | Array | Conditionally Required | Email custom template configuration, required for custom template type, supports multi-language configuration |
email_config.template_custom_configs.language | String | Required | Language, default is the default. Template content can be matched based on the language parameter during delivery |
email_config.template_custom_configs.pre_from_name | String | Optional | Preset sender name |
email_config.template_custom_configs.pre_from_mail | String | Required | Preset sender email |
email_config.template_custom_configs.pre_subject | String | Required | Preset email subject |
email_config.template_custom_configs.template_content | String | Required | Email content, supports HTML. Variables must be enclosed in double curly braces {{} |
email_config.template_custom_configs.pre_param_map | Object | Optional | Default values for variables in email content. Declared as key-value pairs, values must be strings |
pwa_config | Object | Optional | PWA-related configuration, optional |
pwa_config.pwa_platform | String | Optional | PWA platform used. For specific values, contact technical support |
pwa_config.pwa_code | String | Optional | Code in the PWA platform used |
Response Parameters
Field | Type | Option | Description |
---|---|---|---|
code | Integer | Required | Error code, 0 indicates success, others indicate failure |
message | String | Required | Verification code to be validated |
Success Response
{
"code": 0,
"message": "success"
}
Failure Response
{
"code": 3003,
"message": "not contains any channel config"
}
Error Codes
Error Code | HTTP Code | Description |
---|---|---|
1000 | 500 | Internal error |
2001 | 401 | Authentication failed, incorrect token provided |
2002 | 401 | Authentication failed, token expired or disabled |
2004 | 403 | No permission to call this API |
3001 | 400 | Invalid request parameter format, check if it conforms to JSON format |
3002 | 400 | Invalid request parameters, check if they meet the requirements |
3003 | 400 | Business-level parameter error, check the message field for details |
Delete Template
Endpoint
DELETE /v1/template-configs/{templateId}
Authentication
Use HTTP Basic Authentication by adding Authorization in the HTTP Header:
Authorization: Basic ${base64_auth_string}
The base64_auth_string is generated as follows: base64(dev_key:dev_secret)
Request Example
Request Header
DELETE /v1/template-configs/{templateId} HTTP/1.1
Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0
Request Body
None
Request Parameters
{templateId}
in the URL represents the template ID to be deleted, which is defined by the caller when creating the template.
Response Parameters
Field | Type | Option | Description |
---|---|---|---|
code | Integer | Required | Error code, 0 indicates success, others indicate failure |
message | String | Required | Verification code to be validated |
Success Response
{
"code": 0,
"message": "success"
}
Failure Response
{
"code": 4001,
"message": "config not exist"
}
Error Codes
Error Code | HTTP Code | Description |
---|---|---|
1000 | 500 | Internal error |
2001 | 401 | Authentication failed, incorrect token provided |
2002 | 401 | Authentication failed, token expired or disabled |
2004 | 403 | No permission to call this API |
3001 | 400 | Invalid request parameter format, check if it conforms to JSON format |
3002 | 400 | Invalid request parameters, check if they meet the requirements |
4001 | 400 | Template does not exist |
Get All Template List
Currently, this API does not support pagination and will return a brief list of all templates, mainly excluding specific content. If detailed content is needed, please use the detail API.
Endpoint
GET /v1/template-configs
Authentication
Uses HTTP Basic Authentication. Add the Authorization header in the HTTP Header:
Authorization: Basic ${base64_auth_string}
The above base64_auth_string
is generated using the algorithm: base64(dev_key:dev_secret)
Request Example
Request Header
GET /v1/template-configs HTTP/1.1
Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0
Request Body
None
Request Parameters
None
Successful Response
[{
"template_id": "test-template-1", // Custom template ID, unique within the application
"description": "Test Template 1", // Description of the template
"send_channel_strategy": "whatsapp|sms", // Delivery strategy of the template, supports whatsapp/sms/voice/email. Combined strategies use the "|" character to indicate fallback
"brand_name": "Brand Name", // Brand name, used as a signature in template content for certain countries/regions (e.g., required for SMS channels in some countries/regions)
"verify_code_config": { // Configuration for verification codes, returned when the template includes verification code types
"verify_code_type": 1, // Verification code type, range [1,7]
"verify_code_len": 6, // Verification code length, range [4,10]
"verify_code_ttl": 1 // Verification code validity period, range [1,10]. Note: When the strategy includes whatsapp, the value can only be 1, 5, or 10
},
"whatsapp_config": { // Configuration for whatsapp strategy, returned when the delivery strategy includes whatsapp
"template_type": 1 // Whatsapp template type, currently only supports default templates, fixed value of 1
},
"sms_config": { // Configuration for SMS strategy, returned when the delivery strategy includes SMS
"template_type": 2, // SMS template type, values: 1-default template/2-custom template
"template_parts": 1 // Estimated billing parts for the SMS template. If the template is too long, the specific price = billing parts * unit price
},
"voice_config": { // Configuration for voice strategy, returned when the delivery strategy includes voice
"template_type": 1 // Voice template type, currently only supports default templates, fixed value of 1
},
"email_config": { // Configuration for email strategy, returned when the delivery strategy includes email
"template_name": "Email Template Name" // Email template name
},
"pwa_config": { // Configuration related to PWA, returned when PWA configuration is present
"pwa_platform": "xx", // PWA platform used
"pwa_code": "xx" // Code used in the PWA platform
},
"created_time": 1234567890, // Creation time of the template, in timestamp format, accurate to seconds
"status": 1, // Template status, values: 1-Pending Review/2-Approved/3-Rejected
"audit_remark": "xx" // Audit remarks, generally used to view rejection reasons when the review is rejected
},...] // Note: This is an array of objects
Failure Response
{
"code": 4001,
"message": "config not exist"
}
Error Codes
Error Code | HTTP Code | Description |
---|---|---|
1000 | 500 | Internal Error |
2001 | 401 | Authentication failed, incorrect token provided |
2002 | 401 | Authentication failed, token expired or disabled |
2004 | 403 | No permission to call this API |
4001 | 400 | Template does not exist |
Get Template Details
Endpoint
GET /v1/template-configs/{templateId}
Authentication
Uses HTTP Basic Authentication. Add the Authorization header in the HTTP Header:
Authorization: Basic ${base64_auth_string}
The above base64_auth_string
is generated using the algorithm: base64(dev_key:dev_secret)
Request Example
Request Header
GET /v1/template-configs/custom-template-id HTTP/1.1
Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0
Request Body
None
Request Parameters
The {templateId}
in the URL represents the template ID to be retrieved, which is defined by the caller when creating the template.
Successful Response
{
"template_id": "test-template-1", // Custom template ID, unique within the application
"description": "Test Template 1", // Description of the template
"send_channel_strategy": "whatsapp|sms", // Delivery strategy of the template, supports whatsapp/sms/voice/email. Combined strategies use the "|" character to indicate fallback
"brand_name": "Brand Name", // Brand name, used as a signature in template content for certain countries/regions (e.g., required for SMS channels in some countries/regions)
"verify_code_config": { // Configuration for verification codes, returned when the template includes verification code types
"verify_code_type": 1, // Verification code type, range [1,7]
"verify_code_len": 6, // Verification code length, range [4,10]
"verify_code_ttl": 1 // Verification code validity period, range [1,10]. Note: When the strategy includes whatsapp, the value can only be 1, 5, or 10
},
"whatsapp_config": { // Configuration for whatsapp strategy, returned when the delivery strategy includes whatsapp
"template_type": 1 // Whatsapp template type, currently only supports default templates, fixed value of 1
},
"sms_config": { // Configuration for SMS strategy, returned when the delivery strategy includes SMS
"template_type": 2, // SMS template type, values: 1-default template/2-custom template
"template_parts": 1, // Estimated billing parts for the SMS template. If the template is too long, the specific price = billing parts * unit price
"template_custom_config": { // Custom SMS template configuration, valid when the SMS template type is custom
"custom_sub_type": "authentication", // Custom template type, values: authentication-verification code/marketing-marketing/utility-notification
"custom_content": "xxx" // Custom template content. Note: If the subtype is authentication (verification code), it must include the {{code}} variable
}
},
"voice_config": { // Configuration for voice strategy, returned when the delivery strategy includes voice
"template_type": 1 // Voice template type, currently only supports default templates, fixed value of 1
},
"email_config": { // Configuration for email strategy, returned when the delivery strategy includes email
"template_name": "Email Template Name", // Email template name
"template_custom_configs": [{ // Custom email template configuration, valid when the email template type is custom. Note: This is an array of objects, mainly distinguished by language for multiple configurations
"language": "default", // Language, "default" is the default. When sending messages, different template content can be matched based on the language parameter
"pre_from_name": "test", // Preset sender name
"pre_from_mail": "test@test.com", // Preset sender email
"pre_subject": "test", // Preset email subject
"template_content": "Preset email template content, required. Custom variables like {{self}}, verification code is {{code}}", // Email content, supports HTML. Variables need to be enclosed in double curly braces {{}}
"pre_param_map": { // Default values for variables in the email content. If no variable value is specified during sending, the default values below will replace the variables, declared as key-value pairs
"self": "This is the default value for the self variable"
}
}]
},
"pwa_config": { // Configuration related to PWA, returned when PWA configuration is present
"pwa_platform": "xx", // PWA platform used
"pwa_code": "xx" // Code used in the PWA platform
},
"created_time": 1234567890, // Creation time of the template, in timestamp format, accurate to seconds
"status": 1, // Template status, values: 1-Pending Review/2-Approved/3-Rejected
"audit_remark": "xx" // Audit remarks, generally used to view rejection reasons when the review is rejected
}
Failure Response
{
"code": 4001,
"message": "config not exist"
}
Error Codes
Error Code | HTTP Code | Description |
---|---|---|
1000 | 500 | Internal Error |
2001 | 401 | Authentication failed, incorrect token provided |
2002 | 401 | Authentication failed, token expired or disabled |
2004 | 403 | No permission to call this API |
4001 | 400 | Template does not exist |