Sends messages by using a message template. The API operation is available only to China and the US.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes SendMessageWithTemplate

The operation that you want to perform. Set the value to SendMessageWithTemplate.

To String Yes 861503871****

The mobile phone numbers that you want to receive the messages. You must add the country code to the beginning of each mobile phone number. Example: 861503871 ****.

From String Yes Alicloud

The identifier of the sender. If you send the messages to China, specify a signature. You can apply for a signature in the console. If you send the messages to the US, specify a sender ID.

TemplateCode String Yes SMS_0000

The code of the message template.

TemplateParam String No {"code":"1234","product":"ytx"}

The values of the variables that are included in the message template. The values must use the JSON format. If a variable exists in the template, the parameter is required.

Note If line breaks are required in JSON-formatted data, they must meet the relevant requirements that are specified in the standard JSON protocol.
SmsUpExtendCode String No 90999

The extension code of the upstream message.

Response parameters

Parameter Type Example Description
ResponseCode String OK

The status that indicates whether the message sending request was submitted.

NumberDetail Object

The details about the mobile phone number.

Carrier String China Mobile

The carrier that provides the mobile phone number.

Region String Nanjing, Jiangsu

The region to which the mobile phone number belongs.

Country String China

The country to which the mobile phone number belongs.

ResponseDescription String The SMS Send Request was accepted

The description of the status that indicates whether the message sending request was submitted.

Segments String 1

The number of the messages that incurred fees.

To String 861503871****

The mobile phone numbers that you want to receive the messages. You must add the country code to the beginning of each mobile phone number. Example: 861503871 ****.

MessageId String 10080303003****

The ID of the message.

RequestId String F655A8D5-B967-440B-8683-DAD6FF8D****

The ID of the request.

Examples

Sample requests

http(s)://dysmsapi.ap-southeast-1.aliyuncs.com/?Action=SendMessageWithTemplate
&From=Alicloud
&TemplateCode=SMS_0000
&To=861503871****
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<SendMessageWithTemplateResponse>
    <ResponseCode>OK</ResponseCode>
    <NumberDetail>
        <Carrier>China Mobile</Carrier>
        <Region>Nanjing, Jiangsu</Region>
        <Country>China</Country>
    </NumberDetail>
    <ResponseDescription>The SMS Send Request was accepted</ResponseDescription>
    <Segments>1</Segments>
    <To>861503871****</To>
    <MessageId>10080303003****</MessageId>
    <RequestId>F655A8D5-B967-440B-8683-DAD6FF8D****</RequestId>
</SendMessageWithTemplateResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "ResponseCode" : "OK",
  "NumberDetail" : {
    "Carrier" : "China Mobile",
    "Region" : "Nanjing, Jiangsu",
    "Country" : "China"
  },
  "ResponseDescription" : "The SMS Send Request was accepted",
  "Segments" : "1",
  "To" : "861503871****",
  "MessageId" : "10080303003****",
  "RequestId" : "F655A8D5-B967-440B-8683-DAD6FF8D****"
}

Error codes

For a list of error codes, visit the API Error Center.