Custom OTP Code Delivery
If you want to generate verification codes yourself instead of having them generated by the EngageLab platform, you can call this API.
This API is specifically used to send pre-generated verification codes and does not generate verification codes on its own. After sending a verification code, there is no need to call a verification API to validate it.
If you want the EngageLab platform to generate verification codes, you can call the EngageLab OTP Verification Code Delivery API.
Endpoint
POST https://otp.api.engagelab.cc/v1/codes
Authentication
Use HTTP Basic Authentication by adding Authorization to the HTTP header:
Authorization: Basic ${base64_auth_string}
The generation algorithm for base64_auth_string above is: base64(dev_key:dev_secret)
Request Example
Request Header
POST /v1/codes HTTP/1.1
Content-Type: application/json
Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0
Request Body
{
"to": "+8618701235678",
"code": "398210",
"template": {
"id": "test-template-1",
"language": "default",
"params": {
"key1": "value1",
"key2": "value2"
}
}
}
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 phone number or email address, such as +8613800138000 or support@engagelab.com |
| code | String | Required | The custom verification code to send |
| template | JSON Object | Required | Template information. See the second-level parameters below |
| |_ id | String | Required | Template ID |
| |_ language | String | Optional | Template language. The following languages are supported: default Default language zh_CN Simplified Chinese zh_HK Traditional Chinese en English ja Japanese th Thai es Spanish If not provided, the default value is default (the default language). |
| |_ params | JSON Object | Optional | Values for custom template variable keys. If you defined custom variables when creating the template, assign their values here. If not provided, the variable key will be sent directly, such as {{var}}. |
Description of params
- For preset template fields such as
from_id, if theparam_varsfield value is not provided, the presetfrom_idin the template will be used when the message is sent. - If the
param_varsfield value is provided, such asparam_vars:{"from_id":"12345"}, then the template'sfrom_idwill be replaced with12345when the message is sent. - Custom variable fields in the template content that were created during template creation are also assigned values through
param_vars. For example, if the template content isHi {{name}}, your verify code is {{code}}, then the assignment parameterparam_vars:{"name":"Bob"}is required.
Response Parameters
Successful Response
| Field | Type | Required | Description |
|---|---|---|---|
| message_id | String | Required | Message ID, which uniquely identifies a message |
| send_channel | String | Required | Indicates the current delivery channel. Possible values: whatsapp/sms/email/voice |
{
"message_id": "1725407449772531712",
"send_channel": "sms"
}
Please note that the returned send_channel value does not represent the final channel used to deliver the message to the user; it only represents the channel currently in use. For example, if the template strategy is configured so that delivery through the WhatsApp channel will automatically retry through the SMS channel if it fails, then the API response will return the value whatsapp. After a certain period of time, if a delivery failure is detected, the system will 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. The correct 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 made again within the verification code validity period. |
| 4001 | 400 | The related resource does not exist, such as using a non-existent template when sending a template message. |
| 5001 | 400 | Sending failed (general/other) |
| 5011 | 400 | Invalid phone number format |
| 5012 | 400 | Target unreachable |
| 5013 | 400 | Number has been blacklisted |
| 5014 | 400 | Content does not comply with specifications |
| 5015 | 400 | Message intercepted/rejected |
| 5016 | 400 | Internal sending error |
| 5017 | 400 | No sending permission for mainland China |
| 5018 | 400 | Phone malfunction (powered off/service suspended) |
| 5019 | 400 | User has unsubscribed |
| 5020 | 400 | Number not registered/invalid number |
