Batch SMS Sending API
Function
This API is used for the Message & SMS platform to send different SMSs to different users as requested.
Instructions
- Prerequisites
- You have created an SMS application and obtained Application Key, Application Secret, Application Access Address, and Channel No..
- You have applied for an SMS template and obtained the template ID.
- Notes
- An SMS can be sent to a maximum of 500 numbers separated by commas (,). Each number contains a maximum of 21 characters. If there are more than 500 numbers, the SMS fails to be sent to any of the numbers.
- When X-WSSE authentication is used, the difference between the time when a random number is generated and the local time when the request is sent cannot exceed 24 hours. Otherwise, the authentication will fail.
- When AK/SK authentication is used, the difference between the time when a random number is generated and the local time when the request is sent cannot exceed 15 minutes. Otherwise, the authentication will fail.
Type
Method |
POST |
---|---|
URI |
/sms/batchSendDiffSms/v1 |
Communications Protocol |
HTTPS |
Request Parameters
Parameter |
Mandatory |
Type |
Default Value |
Description |
---|---|---|---|---|
Content-Type |
Yes |
String |
None |
The fixed value is application/json. |
Authorization |
Yes |
String |
None |
SDK-HMAC-SHA256 Access="Value of app_key", SignedHeaders="Headers used for signature (lowercase)", Signature="Value calculated using the signature algorithm". For details, see Adding the Signature to the Request Header.
|
X-WSSE |
No (mandatory for X-WSSE authentication) |
String |
None |
The value is UsernameToken Username="Value of app_key", PasswordDigest="Value of PasswordDigest", Nonce="Random string", Created="Time when the random string is generated".
|
X-Sdk-Date |
No (mandatory for AK/SK authentication) |
String |
None |
Format: yyyyMMdd'T'HHmmss'Z'. |
Host |
No |
String |
None |
Destination address of API calling for AK/SK authentication, for example, smsapi.cn-north-4.myhuaweicloud.com:443. |
Programming Language |
Time Format |
---|---|
Java |
yyyy-MM-dd'T'HH:mm:ss'Z' |
PHP |
Y-m-d\TH:i:s\Z |
Python |
%Y-%m-%dT%H:%M:%SZ |
C# |
yyyy-MM-ddTHH:mm:ssZ |
Node.js |
toISOString().replace(/.[0-9]+\Z/, 'Z') Note: In Node.js, delete ms from the time format converted by using toISOString(). |
Go |
2006-01-02T15:04:05Z |
Parameter |
Mandatory |
Type |
Default Value |
Description |
---|---|---|---|---|
from |
Yes |
String(1-21) |
None |
Number from which an SMS is sent.
|
statusCallback |
No |
String(1-1024) |
None |
Callback address of the user for receiving the SMS status report, for example http://my.com/receiveSMSReport.
|
smsContent |
Yes |
None |
Content of an SMS notification. Its size cannot exceed 64 KB. |
|
extend |
No |
String(1-128) |
None |
Extended parameter returned in the status report. Spaces and braces {} are not allowed. |
Parameter |
Mandatory |
Type |
Default Value |
Description |
---|---|---|---|---|
to |
Yes |
String[](1-21999) |
None |
SMS recipient numbers for group sending. The standard format is +{Country code}{Area code}{Terminal number}.
Separate multiple recipient numbers with commas (,). Each number contains a maximum of 21 characters, and a maximum of 500 numbers are supported. |
templateId |
Yes |
String(1-32) |
None |
Unique SMS template ID. Obtain the template ID when applying for an SMS template. templateId must be used together with the templateParas parameter. |
templateParas |
No |
String[] |
None |
Optional when a non-variable template is used. List of SMS template variables, used to configure the variables specified in templateId. This parameter is in the JSONArray format. For details, see Template and Variable Specifications. The number and the length of variables must be consistent with those defined in the template specified by the templateId parameter. For example, if the template specified by templateId contains two variables with lengths of 5 and 6, the variable list must contain two corresponding variables with lengths not exceeding 5 and 6, respectively. If the template content is "You have ${NUM_5} parcels delivered to ${TXT_6}, this parameter can be set to '["3","Gate of People's Park"]'. |
Response Parameters
Parameter |
Mandatory |
Type |
Default Value |
Description |
---|---|---|---|---|
code |
Yes |
String(1-7) |
None |
Result code returned after the request is sent. |
description |
Yes |
String(1-512) |
None |
Description of the result code. |
result |
No |
None |
SMS body. A response does not contain this parameter when an error occurs. |
Parameter |
Mandatory |
Type |
Default Value |
Description |
---|---|---|---|---|
smsMsgId |
Yes |
String(1-50) |
None |
Unique SMS ID. |
from |
Yes |
String(1-21) |
None |
Number from which an SMS is sent. |
originTo |
Yes |
String(1-21) |
None |
Number to which an SMS is sent. |
status |
Yes |
String(1-7) |
None |
SMS status code. The following describes some SMS status codes. For details about the handling suggestions, see API Error Codes.
|
createTime |
Yes |
String(1-20) |
None |
Time when the SMS resource was created, that is, the UTC time when the Message & SMS platform received an SMS request from a user. Format: yyyy-MM-dd'T'HH:mm:ss'Z' |
Result Codes
Response Code |
Result Code |
Message |
Solution |
---|---|---|---|
200 |
000000 |
Success. |
No action is required. |
400 |
E000000 |
System error. |
Check whether the templateParas parameter is set correctly according to the code example. If the problem persists, contact the administrator. |
E000001 |
Authorization not contained in the HTTP header. |
Check whether the HTTP message header contains the Authorization field. |
|
E000002 |
realm not contained in Authorization. |
Check whether the Authorization field contains the realm attribute. |
|
E000003 |
profile not contained in Authorization. |
Check whether the Authorization field contains the profile attribute. |
|
E000004 |
The value of realm in Authorization must be SDP. |
Check whether the value of realm in the Authorization field is SDP. |
|
E000005 |
The value of profile in Authorization must be UsernameToken. |
Check whether the value of profile in the Authorization field is UsernameToken. |
|
E000006 |
The value of type in Authorization must be app_key. |
Check whether the value of type in the Authorization field is Appkey. |
|
E000007 |
type not contained in Authorization. |
Check whether the Authorization field contains the type attribute. |
|
E000008 |
WSSE not contained in Authorization. |
Check whether the Authorization field contains the WSSE field. |
|
E000020 |
X-WSSE not contained in the HTTP header. |
Check whether the HTTP message header contains the X-WSSE field. |
|
E000021 |
UserName not contained in X-WSSE. |
Check whether the X-WSSE field contains the UserName attribute. |
|
E000022 |
Nonce not contained in X-WSSE. |
Check whether the X-WSSE field contains the Nonce attribute. |
|
E000023 |
Created not contained in X-WSSE. |
Check whether the X-WSSE field contains the Created attribute. |
|
E000024 |
PasswordDigest not contained in X-WSSE. |
Check whether the X-WSSE field contains the PasswordDigest attribute. |
|
E000025 |
The format of Created is incorrect. |
Check whether the format of the Created attribute in the X-WSSE field is correct. |
|
E000026 |
UsernameToken not contained in X-WSSE. |
Check whether the X-WSSE field contains the UsernameToken attribute. |
|
E000027 |
Invalid request. |
Check whether the parameters in the request are valid based on the parameter description and requirements in the API reference. |
|
E000503 |
The parameter format is incorrect. |
Check whether the parameter format is correct. |
|
E000510 |
The SMS fails to be sent. For details, see status. |
Check the value of status in the response parameter to determine the cause of the failure, modify the parameter value, and resend the SMS. |
|
E000623 |
Number of SMSs sent by the SP reached the limit. |
Contact the operation manager to increase the maximum number of SMSs sent by the SP. |
|
401 |
E000101 |
Authentication failed. |
Check whether the values of Authorization and X-WSSE are correct. |
E000102 |
Invalid app_key. |
Check whether app_key in the request is correct. If app_key is correct, check whether the application access address (obtained from the Application Management page on the console) is correct. |
|
E000103 |
The status of the app_key is unavailable. |
Contact the administrator to check whether the app_key status is normal. |
|
E000104 |
Invalid app_secret. |
Check whether app_secret in the request is correct. |
|
E000105 |
Invalid digest. |
Check whether PasswordDigest in the request is correct. |
|
E000106 |
The app_key is not allowed to invoke this API. |
Contact the administrator to check whether the application corresponding to the app_key supports SMS capability exposure. |
|
E000109 |
The user status is deactivated. |
Contact the administrator to activate the user. |
|
E000110 |
Time out limit. |
When X-WSSE authentication is used, make sure that there is not too much difference between the time when the random string is generated and the local time when the request is sent. For details, contact the administrator. |
|
E000111 |
Incorrect username or password. |
The user information corresponding to app_key cannot be found. Contact the administrator. |
|
E000112 |
The subscriber status is frozen. |
If the account is frozen due to arrears, top up the account by referring to Topping Up an Account (Prepaid Direct Customers). Then, the account is automatically unfrozen. If the account is frozen due to violation, modify the service and contact the operation manager to apply for account unfreezing. |
|
403 |
E000620 |
The app client ip is not in ip white list. |
|
API Example
- Example request 1
POST /sms/batchSendDiffSms/v1 HTTP/1.1 x-real-ip: 10.10.10.168 x-real-port: 10443 host: ompap.inner content-length: 315 date: Fri, 13 Apr 2018 06:48:35 GMT authorization: WSSE realm="SDP",profile="UsernameToken",type="Appkey" x-wsse: UsernameToken Username="ZRBRz4bAXoFgEH7o4Ew308eXc1RA",PasswordDigest="NDA1MWIwNjI2ZTkyNWFlM2FhMTE5NDE1YTk5NjU1YWE4NjNlZTY1MmRhYzkxZGViNzczZjdjMjkzZWQ4ZjAwNA==",Nonce="ac1c911c4792492687f8f6b2264a491e",Created="2018-05-26T00:35:30Z" accept: application/json content-type: application/json {"from":"1069031221280012","smsContent":[{"to":["+8615512345678","+8615512345679"],"templateId":"abcdefghabcdefghabcdefghabcdefgh","templateParas":["062569"]},{"to":["+8615512345680"],"templateId":"hgfedcbahgfedcbahgfedcbahgfedcba","templateParas":["605623"]}],"statusCallback":"http://205.145.111.168:9330/report"}
- Example request 2
POST /sms/batchSendDiffSms/v1 HTTP/1.1 Host: smsapi.cn-north-4.myhuaweicloud.com:443 X-Sdk-Date: 20230519T005038Z Authorization: SDK-HMAC-SHA256 Access=uxOF5yvM0H3C0t5G0xc272g7hA2I, SignedHeaders=content-type;host;x-sdk-date, Signature=082f05bcd561e291a7469939980c022f721a581967cc30eb3725c7aea4bd634d content-length: 315 Content-Type: application/json {"from":"1069********0012","smsContent":[{"to":["+86155****5678","+86155****5679"],"templateId":"abcdefghabcdefghabcdefghabcdefgh","templateParas":["062569"]},{"to":["+86155****45680"],"templateId":"hgfedcbahgfedcbahgfedcbahgfedcba","templateParas":["605623"]}],"statusCallback":"http://205.145.111.168:9330/report"}
- Response Example
HTTP/1.1 200 OK Date: Fri, 13 Apr 2018 06:46:04 GMT Server: WebServer Content-Type: application/json;charset=UTF-8 Content-Length: 541 {"result":[{"originTo":"+8615512345678","createTime":"2018-05-25T16:34:34Z","from":"1069031221280012","smsMsgId":"5963c5be-f189-4c0c-ab2e-7cab0c42c798_52","status":"000000"},{"originTo":"+8615512345679","createTime":"2018-05-25T16:34:34Z","from":"1069031221280012","smsMsgId":"5963c5be-f189-4c0c-ab2e-7cab0c42c798_53","status":"000000"},{"originTo":"+8615512345680","createTime":"2018-05-25T16:34:34Z","from":"1069031221280012","smsMsgId":"5963c5be-f189-4c0c-ab2e-7cab0c42c798_54","status":"000000"}],"code":"000000","description":"Success"}
Demos
Download the following demos to quickly develop applications.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.