CreateUSMSTemplate
Create SMS Template
API Description
Create and submit an SMS template. The template must be approved before it can be used.
Request Information
- Get API Key:
ACCESSKEY_ID:ACCESSKEY_SECRET - Request Method:
POST - Request Path:
/api/v1/usms/USMSTemplate - 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 |
|---|---|---|---|---|
| Purpose | int | Yes | Template purpose: 1-Verification code, 2-Notification, 3-Marketing | 1 |
| TemplateName | string | Yes | Template name | "MyTemplate" |
| Template | string | Yes | Template content | "Your verification code is {1}" |
| Remark | string | No | Remarks | "For user login verification" |
| Instruction | string | No | Usage instructions | - |
| BrevityCode | string | No | Short code | - |
| Tags | []int | No | Tag list | [1, 2] |
| VariableAttr | string | No | Template variable attributes | - |
Request Examples
- CURL
- Golang
- Java
- Python
- PHP
curl -X POST "https://api.uspeedo.com/api/v1/usms/USMSTemplate" \
-H "Content-Type: application/json" \
-H "Authorization: Basic $(echo -n 'YOUR_ACCESSKEY_ID:YOUR_ACCESSKEY_SECRET' | base64)" \
-d '{
"Purpose": 1,
"TemplateName": "MyTemplate",
"Template": "Your verification code is {1}, valid for 5 minutes",
"Remark": "For user login verification"
}'
package main
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
url := "https://api.uspeedo.com/api/v1/usms/USMSTemplate"
// Prepare request body
requestBody := map[string]interface{}{
"Purpose": 1,
"TemplateName": "MyTemplate",
"Template": "Your verification code is {1}, valid for 5 minutes",
"Remark": "For user login verification",
}
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 CreateUSMSTemplate {
public static void main(String[] args) {
try {
String url = "https://api.uspeedo.com/api/v1/usms/USMSTemplate";
// Prepare request body
String jsonBody = "{\n" +
" \"Purpose\": 1,\n" +
" \"TemplateName\": \"MyTemplate\",\n" +
" \"Template\": \"Your verification code is {1}, valid for 5 minutes\",\n" +
" \"Remark\": \"For user login verification\"\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
import json
def create_usms_template():
url = "https://api.uspeedo.com/api/v1/usms/USMSTemplate"
# Prepare request body
payload = {
"Purpose": 1,
"TemplateName": "MyTemplate",
"Template": "Your verification code is {1}, valid for 5 minutes",
"Remark": "For user login verification"
}
# 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__":
create_usms_template()
<?php
function createUSMSTemplate() {
$url = "https://api.uspeedo.com/api/v1/usms/USMSTemplate";
// Prepare request body
$data = array(
"Purpose" => 1,
"TemplateName" => "MyTemplate",
"Template" => "Your verification code is {1}, valid for 5 minutes",
"Remark" => "For user login verification"
);
$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);
}
createUSMSTemplate();
?>
Response Format
Success Response
{
"RetCode": 0,
"Message": "success",
"TemplateId": "template_123456"
}
Response Field Description
| Field Name | Type | Description |
|---|---|---|
| RetCode | int | Return code, 0 indicates success |
| Message | string | Return message |
| TemplateId | string | Created template ID, used for subsequent SMS sending |
Error Response
{
"RetCode": 215392,
"Message": "Invalid parameter [TemplateName]"
}