SendBatchUSMSMessage
Send Batch SMS
API Description
Send SMS messages in batch. Supports sending to multiple phone numbers at once.
Request Information
- Get API Key:
ACCESSKEY_ID:ACCESSKEY_SECRET - Request Method:
POST - Request Path:
/api/v1/usms/SendBatchUSMSMessage - Content-Type:
application/json
Request Parameters
Header Parameters
| Parameter Name | Type | Required | Description | Example Value |
|---|---|---|---|---|
| Content-Type | string | Yes | Request content type | "application/json" |
| Authorization | string | Yes | HTTP Basic authentication | "Basic $(echo -n 'accesskeyId:accesskeySecret' |
Body Parameters
| Parameter Name | Type | Required | Description | Example Value |
|---|---|---|---|---|
| TaskContent | array | Yes | Send task list | See description below |
TaskContent Array Element Description
Each element contains the following fields:
| Parameter Name | Type | Required | Description | Example Value |
|---|---|---|---|---|
| TemplateId | string | Yes | Template ID | "template_id_1" |
| SenderId | string | Yes | Sender identifier (sender name) | "USpeedo" |
| Target | array | Yes | Target phone number list | See description below |
Target Array Element Description
Each element contains the following fields:
| Parameter Name | Type | Required | Description | Example Value |
|---|---|---|---|---|
| Phone | string | Yes | Phone number | "13800138000" |
| TemplateParams | array | No | Template parameters (fill according to template variables) | ["123456"] |
Request Examples
- CURL
- Golang
- Java
- Python
- PHP
curl -X POST "https://api.uspeedo.com/api/v1/usms/SendBatchUSMSMessage" \
-H "Content-Type: application/json" \
-H "Authorization: Basic $(echo -n 'YOUR_ACCESSKEY_ID:YOUR_ACCESSKEY_SECRET' | base64)" \
-d '{
"TaskContent": [
{
"TemplateId": "template_id_1",
"SenderId": "USpeedo",
"Target": [
{
"Phone": "13800138000",
"TemplateParams": ["123456"]
}
]
}
]
}'
package main
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
)
type TargetPhone struct {
Phone string `json:"Phone"`
TemplateParams []string `json:"TemplateParams,omitempty"`
}
type SendInfo struct {
TemplateId string `json:"TemplateId"`
SenderId string `json:"SenderId"`
Target []TargetPhone `json:"Target"`
}
type SendBatchRequest struct {
TaskContent []SendInfo `json:"TaskContent"`
}
func main() {
url := "https://api.uspeedo.com/api/v1/usms/SendBatchUSMSMessage"
// Prepare request body
requestBody := SendBatchRequest{
TaskContent: []SendInfo{
{
TemplateId: "template_id_1",
SenderId: "USpeedo",
Target: []TargetPhone{
{
Phone: "13800138000",
TemplateParams: []string{"123456"},
},
{
Phone: "13900139000",
TemplateParams: []string{"654321"},
},
},
},
},
}
jsonData, _ := json.Marshal(requestBody)
// Create request
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json")
// Set HTTP Basic authentication
accesskeyId := "YOUR_ACCESSKEY_ID"
accesskeySecret := "YOUR_ACCESSKEY_SECRET"
auth := base64.StdEncoding.EncodeToString([]byte(accesskeyId + ":" + accesskeySecret))
req.Header.Set("Authorization", "Basic "+auth)
// Send request
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Printf("Request failed: %v\n", err)
return
}
defer resp.Body.Close()
// Read response
body, _ := io.ReadAll(resp.Body)
fmt.Printf("Response status code: %d\n", resp.StatusCode)
fmt.Printf("Response content: %s\n", string(body))
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class SendBatchUSMSMessage {
public static void main(String[] args) {
try {
String url = "https://api.uspeedo.com/api/v1/usms/SendBatchUSMSMessage";
// Prepare request body
String jsonBody = "{\n" +
" \"TaskContent\": [\n" +
" {\n" +
" \"TemplateId\": \"template_id_1\",\n" +
" \"SenderId\": \"USpeedo\",\n" +
" \"Target\": [\n" +
" {\n" +
" \"Phone\": \"13800138000\",\n" +
" \"TemplateParams\": [\"123456\"]\n" +
" },\n" +
" {\n" +
" \"Phone\": \"13900139000\",\n" +
" \"TemplateParams\": [\"654321\"]\n" +
" }\n" +
" ]\n" +
" }\n" +
" ]\n" +
"}";
// Create connection
URL apiUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) apiUrl.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
// Set HTTP Basic authentication
String accesskeyId = "YOUR_ACCESSKEY_ID";
String accesskeySecret = "YOUR_ACCESSKEY_SECRET";
String auth = accesskeyId + ":" + accesskeySecret;
String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes(StandardCharsets.UTF_8));
conn.setRequestProperty("Authorization", "Basic " + encodedAuth);
// Send request body
conn.setDoOutput(true);
try (OutputStream os = conn.getOutputStream()) {
byte[] input = jsonBody.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
// Read response
int responseCode = conn.getResponseCode();
System.out.println("Response status code: " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println("Response content: " + response.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
import requests
import base64
def send_batch_usms_message():
url = "https://api.uspeedo.com/api/v1/usms/SendBatchUSMSMessage"
# Prepare request body
payload = {
"TaskContent": [
{
"TemplateId": "template_id_1",
"SenderId": "USpeedo",
"Target": [
{
"Phone": "13800138000",
"TemplateParams": ["123456"]
},
{
"Phone": "13900139000",
"TemplateParams": ["654321"]
}
]
}
]
}
# Set HTTP Basic authentication
accesskey_id = "YOUR_ACCESSKEY_ID"
accesskey_secret = "YOUR_ACCESSKEY_SECRET"
credentials = base64.b64encode(f"{accesskey_id}:{accesskey_secret}".encode()).decode()
headers = {
"Content-Type": "application/json",
"Authorization": f"Basic {credentials}"
}
# Send request
response = requests.post(url, json=payload, headers=headers)
print(f"Response status code: {response.status_code}")
print(f"Response content: {response.text}")
return response.json() if response.status_code == 200 else None
if __name__ == "__main__":
send_batch_usms_message()
<?php
function sendBatchUSMSMessage() {
$url = "https://api.uspeedo.com/api/v1/usms/SendBatchUSMSMessage";
// Prepare request body
$data = array(
"TaskContent" => array(
array(
"TemplateId" => "template_id_1",
"SenderId" => "USpeedo",
"Target" => array(
array(
"Phone" => "13800138000",
"TemplateParams" => array("123456")
),
array(
"Phone" => "13900139000",
"TemplateParams" => array("654321")
)
)
)
)
);
$jsonData = json_encode($data);
// Set HTTP Basic authentication
$accesskeyId = "YOUR_ACCESSKEY_ID";
$accesskeySecret = "YOUR_ACCESSKEY_SECRET";
$auth = base64_encode($accesskeyId . ":" . $accesskeySecret);
// Initialize cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Authorization: Basic " . $auth
));
// Execute request
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Response status code: " . $httpCode . "\n";
echo "Response content: " . $response . "\n";
return json_decode($response, true);
}
sendBatchUSMSMessage();
?>
Response Format
Success Response
{
"RetCode": 0,
"Message": "success",
"SessionNo": ["session_no_1", "session_no_2"],
"FailedTargetPhones": []
}
Response Field Description
| Field Name | Type | Description |
|---|---|---|
| RetCode | int | Return code, 0 indicates success |
| Message | string | Return message |
| SessionNo | array | Session number list, used for querying send status |
| FailedTargetPhones | array | List of failed phone numbers, each element contains: Phone (phone number), TemplateParams (template parameters), FailureReason (failure reason) |
Error Response
{
"RetCode": 215392,
"Message": "Invalid parameter [TemplateId]"
}
Common Error Codes
| Error Code | Description |
|---|---|
| 0 | Success |
| 215392 | Parameter error |
| 215397 | Missing required parameter |
| 215400 | Server error |