Sends a text message by using a template.

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 No SendMessageWithTemplate

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

SendMessageWithTemplate*.

TemplateCode String Yes SMS_0000

Template code.

To String Yes 86137xxx688

The mobile phone numbers to receive the text messages. You must add the country code to the beginning of each mobile phone number. For example, 86137 xxx688.

From String No Alicloud

The ID of the sender.

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

The values of the variables that are included in the text message template. The values must use the JSON format.

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

The extension code of the upstream text message.

Response parameters

Parameter Type Example Description
MessageId String 1008030xxx3003

The ID of the text message.

NumberDetail Struct

The details of the mobile phone number.

Carrier String China Mobile

The carrier that provides the mobile phone number.

Country String China

The country to which the mobile phone number belongs.

Region String Nanjing, Jiangsu

The region to which the mobile phone number belongs.

ResponseCode String OK

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

ResponseDescription String The SMS Send Request was accepted

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

Segments String 1

The number of the text messages that incurred fees.

To String 8681xxx810

The mobile phone numbers to receive the text messages. You must add the country code to the beginning of each mobile phone number. For example, 86137 xxx688.

Examples

Sample requests

http(s)://dysmsapi.ap-southeast-1.aliyuncs.com? Action=SendMessageWithTemplate
&TemplateCode=SMS_0000
&To=86137***688
&From=Alicloud
&TemplateParam={"code":"1234","product":"ytx"}
&SmsUpExtendCode=90999
&<Common request parameters>

Sample success responses

XML format

<SendMessageWithTemplateResponse>
      <MessageId>1008030xxx3003</MessageId>
        <NumberDetail>
            <Carrier>China Mobile</Carrier>
            <Country>China</Country>
            <Region>Nanjing, Jiangsu</Region>
        </NumberDetail>
    <ResponseCode>OK</ResponseCode>
    <ResponseDescription>The SMS Send Request was accepted</ResponseDescription>
    <Segments>1</Segments>
    <To>86137xxx688</To>
</SendMessageWithTemplateResponse>

JSON format

{
    "MessageId": "1008030xxx3003",
    "NumberDetail": {
        "Carrier": "China Mobile",
        "Country": "China",
        "Region": "Nanjing, Jiangsu"
        },
    "ResponseCode": "OK",
    "ResponseDescription": "The SMS Send Request was accepted",
    "Segments": "1",
    "To": "86137xxx688"
}

Error code

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