Sends a text message by using a template. You can sent the message 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 automatically 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.

From String Yes Alicloud

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

TemplateCode String Yes SMS_0000

The code of the template.

To String Yes 861503871****

The mobile phone number that is used to receive the text message. You must add the country code to the beginning of the mobile phone number. Example: 861503871 ****.

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. This parameter is required if a variable exists in the template.

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 10080303003****

The ID of the text message.

NumberDetail Struct

The details about 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 861503871****

The mobile phone number that was used to receive the text message. Format: Country code + Mobile phone number. Example: 861503871 ****.

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

<SendMessageWithTemplateResponse>
  <MessageId>10080303003****</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>861503871****</To>
</SendMessageWithTemplateResponse>

JSON format

{
    "MessageId": "10080303003****",
    "NumberDetail": {
        "Carrier": "China Mobile",
        "Country": "China",
        "Region": "Nanjing, Jiangsu"
        },
    "ResponseCode": "OK",
    "ResponseDescription": "The SMS Send Request was accepted",
    "Segments": "1",
    "To": "861503871****"
}

Error codes

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