Custom Messages Delivery
If you have created custom template content on the OTP platform, call this API to send custom message content.
Endpoint
POST https://otp.api.engagelab.cc/v1/custom-messages
Authentication
Use HTTP Basic Authentication for authentication, and add Authorization to the HTTP header:
Authorization: Basic ${base64_auth_string}
The generation algorithm for base64_auth_string is: base64(dev_key:dev_secret)
Request Format
Request Headers
POST /v1/custom-messages HTTP/1.1
Content-Type: application/json
Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0
Request Body
{
"to": "+8618701235678",
"template": {
"id": "test-template-1",
"params": {
"code": "codevalue",
"var1": "value1"
}
}
}
Request Parameters
A request object is expressed in JSON format, so the request header must include Content-Type: application/json.
| Parameter | Type | Required | Description |
|---|---|---|---|
| to | String | Required | Delivery target: a mobile phone number or email address, such as +8613800138000 or support@engagelab.com |
| template | JSON Object | Required | Template information. See the nested parameters below |
| |_ id | String | Required | Template ID |
| |_ params | JSON Object | Optional | Template parameters |
| _ |_ code | String | Optional | Required when the template type is a verification code |
| _ |_ var | String | Optional | Value of the custom template variable key. If you defined custom variables when creating the template, assign values to them here. If not provided, the variable key will be delivered directly, such as {{var1}} |
Notes on params
- For preset template variables such as
{{brand_name}},{{ttl}}, and{{pwa_url}}, you do not need to pass them. The system automatically replaces them with the content specified when the template was created. - If the template type is a verification code, you must pass the
{{code}}variable; otherwise, an error will be returned. - If the template content contains custom variable fields defined when the template was created, assign values to them through
paramsas well. For example, for the template contentHi {{name}}, your verify code is {{code}}, you need to assign the parameterparams: {"name":"Bob"}.
Request Examples
1. Send a custom verification code
{
"to": "+8618701235678",
"template": {
"id": "code-template",
"params": {
"code": "123456"
}
}
}
2. Send custom notification content
{
"to": ["+8618701235678"],
"template": {
"id": "notification-template",
"params": {
"order": "123456"
}
}
}
3. Send custom marketing content
{
"to": ["+8618701235678"],
"template": {
"id": "marketing-template",
"params": {
"name": "EngageLab",
"promotion": "30%"
}
}
}
Response Parameters
Successful Response
| Field | Type | Required | Description |
|---|---|---|---|
| message_id | String | Required | Message ID that uniquely identifies a message |
| send_channel | String | Required | Indicates the channel currently used for delivery. Possible values: whatsapp, sms, email, voice |
{
"message_id": "1725407449772531712",
"send_channel": "sms"
}
Note that the returned send_channel value does not represent the final channel used to deliver the message to the user. It only indicates the channel currently being used. For example, if the strategy configured in the template specifies that when WhatsApp delivery fails it should automatically retry through the SMS channel, the API response will return whatsapp. After delivery failure is detected after a certain period of time, the system will then send through the SMS channel.
Failed Response
The HTTP status code is 4xx or 5xx, and the response body contains the following fields:
| Field | Type | Required | Description |
|---|---|---|---|
| code | int | Required | Error code. For details, see Error Codes |
| message | String | Required | Error details |
{
"code": 5001,
"message": "sms send fail"
}
Error Codes
| Error Code | HTTP Code | Description |
|---|---|---|
| 1000 | 500 | Internal error |
| 2001 | 401 | Authentication failed. A valid token was not provided |
| 2002 | 401 | Authentication failed. The token has expired or has been disabled |
| 2004 | 403 | No permission to call this API |
| 3001 | 400 | Invalid request parameter format. Please check whether the JSON content matches the required parameter format |
| 3002 | 400 | Invalid request parameters. Please check whether the request parameters meet the requirements |
| 3003 | 400 | Invalid request parameters. Related business validation failed. Refer to the error description in the message field for details |
| 3004 | 400 | Frequency limit exceeded. For the same template and the same target user, delivery cannot be triggered again within the validity period of the verification code |
| 4001 | 400 | Related resource does not exist. For example, a nonexistent template was used when sending a template message |
| 5001 | 400 | Send failed (general/other) |
| 5011 | 400 | Invalid mobile phone number format |
| 5012 | 400 | Target unreachable |
| 5013 | 400 | Number has been added to the blacklist |
| 5014 | 400 | Content does not comply with the specifications |
| 5015 | 400 | Message intercepted/rejected |
| 5016 | 400 | Internal sending error |
| 5017 | 400 | No permission to send to mainland China |
| 5018 | 400 | Mobile device issue (powered off/service suspended) |
| 5019 | 400 | User has unsubscribed |
| 5020 | 400 | Number is not registered/invalid number |
