API SMS Sending
If you wish to automate the sending of notification and marketing SMS without generating them through the EngageLab platform, you can call this API. Specify the SMS template ID and target recipients, and the system will automatically send SMS based on the template content.
Platform Configuration
Before calling, you need to complete the following configurations in the EngageLab NewSMS console:
SMS Template Setup: Before calling the API, please go to the Template Management Page to customize and submit SMS templates. The template can only be used after it has been approved and you have obtained the template ID.
API Key Configuration: Go to the API Key Page to create an API Basic authentication key.
Call Process
Please refer to the following process to call the API for sending SMS. If you have any questions, please contact customer service.
Call URL
POST https://smsapi.engagelab.cc/v1/messages
Call Authentication
Use HTTP Basic Authentication for verification. Add Authorization in the HTTP Header:
Authorization: Basic ${base64_auth_string}
The generation algorithm for the above base64_auth_string is: base64(dev_key:dev_secret)
Request Format
Request Header
POST /v1/messages HTTP/1.1
Content-Type: application/json
Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0
Request Body
{
"to_ids": [
"8613138283670"
],
"plan_name": "test",
"template": {
"id": 1970314609822883800,
"language": "en",
"params": {
"content": "Verification code: 039487, will expire in 5 minutes. You are trying to create your"
}
},
"source": 1
}
Request Parameters
A request object is expressed in JSON format, so the request header needs to include Content-Type: application/json.
Name | Location | Type | Required | Chinese Name | Description |
---|---|---|---|---|---|
Authorization | header | array[string] | No | none | |
body | body | object | No | none | |
» to_ids | body | [string] | Yes | ID list to send | If there is only one, just pass one |
» plan_name | body | string | No | Plan Name | Optional, default shows "-" if not filled |
» schedule_time | body | integer | No | Scheduled Time | Do not pass this parameter for non-scheduled sending, timestamp |
» template | body | object | Yes | ||
»» id | body | string | Yes | none | |
»» language | body | string | Yes | none | |
»» params | body | object | Yes | none | |
»»» custom_param | body | string | Yes | none | |
» custom_args | body | object | Yes | Custom Parameters |
If you have customized variables when creating the template, pass values for them here. If not passed, the variable key will be sent directly, such as {{var1}}.
Explanation for params
- For template preset variables such as {{brand_name}}, {{ttl}}, {{pwa_url}}, etc., there is no need to pass them; the system will automatically replace them with the content specified when creating the template.
- For custom variable fields in the template content when creating the template, assign values through params. For example, if the template content is
Hi {{name}}, welcome to EngageLab
, you need to assign the parameterparams:{"name":"Bob"}
.
Request Examples
1. Sending Custom Notification Content:
{
"to": "+8618701235678",
"template":{
"id":"notification-template",
"params": {
"order":"123456"
}
}
}
2. Sending Custom Marketing Content:
{
"to": "+8618701235678",
"template":{
"id":"marketing-template",
"params": {
"name":"EngageLab",
"promotion":"30%"
}
}
}
Response Parameters
Successful Response
The HTTP status code is 200, and the response body contains the following fields:
Field | Type | Required | Description |
---|---|---|---|
message_id | String | Yes | Message ID, uniquely identifies a message |
to_id | String | Yes | Phone number sent to |
{
"to_id": "8613138283670",
"message_id": "1971029055205646336"
}
Failed Response
The HTTP status code is 4xx or 5xx, and the response body contains the following fields:
Field | Type | Required | Description |
---|---|---|---|
err_code | int | Yes | Error code, see Error Codes for details |
err_msg | String | Yes | Error details |
{
"err_msg": "sms send failed",
"err_code": 10013
}
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 | Invalid request parameters, related business validation failed, see the error description in the message field |
3004 | 400 | Exceeded frequency limit, cannot resend to the same user with the same template within the verification code validity period |
4001 | 400 | Related resource does not exist, such as using a non-existent template for template message delivery |
5001 | 400 | Verification code message delivery failed, see the error description in the message field |