CreateSmsTemplate

Updated at:

A message template defines the content of an SMS message. This content includes the message text and any variables. You can create templates for various business needs, such as sending verification codes, notifications, or promotional messages. A template must be approved before you can use it to send messages.

Operation description

  • For details on the API changes for signatures and templates, see the Announcement on Signature and Template API Updates for Short Message Service.

  • Wait at least 30 seconds between API calls when applying for a message template.

  • Message templates you apply for via the API are synchronized to the Short Message Service console. For details on how to manage message templates in the console, see Message templates.

  • After you submit a template for review, you can call the GetSmsTemplate API to query the template's review status and details. You can also configure status reports to receive the template's review status through TemplateSmsReport.

  • Message templates for Chinese mainland messages and international messages are not interchangeable. Apply for message templates based on your use case.

  • Only enterprise-verified users can apply for message templates for promotional messages and international messages. For details on the permission differences between individual and enterprise users, see Usage notes.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

dysms:CreateSmsTemplate

none

*All Resource

*

None None

Request parameters

Parameter

Type

Required

Description

Example

TemplateName

string

Yes

The template name. The name must be 30 characters or less.

验证码

TemplateContent

string

Yes

The template content. The content must be 500 characters or less.

The template content and variables must comply with the SMS Template Specifications. Templates that do not comply may be rejected. You can find common template examples on the Apply for Template page. Using these examples can speed up the review process and increase the approval rate. For variable specifications, see Variable Specifications for the TemplateContent Parameter.

您正在申请手机注册,验证码为:${code},5分钟内有效!

Remark

string

No

Describe the business scenario for the SMS messages, or provide a URL for online scenarios. You must also provide a complete SMS example with actual values for any variables. Complete information increases the chance of template approval. Templates that do not provide this information as specified may be rejected.

申请验证码短信

TemplateType

integer

Yes

The SMS type. Valid values:

  • 0: verification code.

  • 1: notification message.

  • 2: promotional message.

  • 3: international/Hong Kong, Macao, and Taiwan messages.

Note

Only enterprise-verified users can apply for promotional messages or international/Hong Kong, Macao, and Taiwan messages. For more information about the differences in privileges between individual and enterprise users, see Usage Notes.

0

RelatedSignName

string

No

The name of the signature to associate with the template. The signature must be an approved signature.

Important
  • This parameter is required if TemplateType is set to 0, 1, or 2.

  • Associating a signature can expedite the review process. The signature associated here is unrelated to the one you select when sending SMS messages.

验证码签名

TemplateRule

string

No

The rules for variables in the template. For instructions on how to define these rules, see Sample Document.

Note
  • This parameter is required if the message template contains variables.

{"code":"characterWithNumber2"}

MoreData

array

No

Additional information. You can upload supporting documents or business screenshots to help reviewers better understand your business scenario. If you are applying for a promotional message template (where TemplateType is 2), you must upload user authorization materials. For more information, see Specifications for Uploading User Authorization Materials.

string

No

The OSS object key for the uploaded file. For instructions on how to upload a file, see Upload a file to OSS.

10098689758*****/1234qwe.png

ApplySceneContent

string

No

The business scenario.

  • If the associated signature's use case is "Live App", ApplySceneContent must be an app URL that starts with http:// or https://.

  • This parameter is required if the associated signature's use case is "Registered Trademark Name" or "organization name".

http://www.aliyun.com/

IntlType

integer

No

The type of the template for international/Hong Kong, Macao, and Taiwan messages. This parameter is required when TemplateType is set to 3. Valid values:

  • 0: notification message.

  • 1: promotional message.

  • 2: verification code.

0

TrafficDriving

string

No

Warning To control the security of SMS content, messages that contain traffic-driving information, such as phone numbers and links, may be blocked by carriers, which can lead to delivery failures. To reduce this risk, we recommend that you avoid including such information in message templates.

A JSON string that contains a list of traffic-driving information.

Important The value must be a JSON array serialized into a string.

1. Fields

{ "trafficDrivingType":"traffic driving type", "trafficDrivingContent":"traffic driving content", "variableName":"variable name", "companyName":"organization name", "organizationCode":"unified social credit code", "icpNo":"ICP filing or license number", "icpPicOssKey":"OSS key of the ICP filing screenshot", "companyDifferentFromSignQuaReason":"Reason for the discrepancy between the organization name and the signature qualification" }

2. Notes

  • If the content is not a variable, do not pass the variableName parameter.

  • If the organization name is different from the one in the signature qualification, pass the companyDifferentFromSignQuaReason parameter.

  • If trafficDrivingType is set to DOMAIN, all parameters in this object are required.

  • If trafficDrivingType is set to another value, pass the trafficDrivingType, trafficDrivingContent, variableName (if applicable), companyName, organizationCode, and companyDifferentFromSignQuaReason (if applicable) parameters.

3. trafficDrivingType enum values

Warning Due to regulatory requirements, mobile phone numbers are not supported.
  • DOMAIN: A domain link.

  • FIXED_PHONE: Fixed-line phone.

  • 400_PHONE: Phone number prefixed with 400.

  • 800_PHONE: Phone number prefixed with 800.

  • 95_PHONE: Phone number prefixed with 95.

  • 96_PHONE: Phone number prefixed with 96.

  • 1_PHONE: A 3- to 8-digit phone number that starts with 1.

  • OTHER_PHONE: Other phone number.

[{"trafficDrivingType":"DOMAIN","trafficDrivingContent":"aliyun.com","companyName":"阿里云计算有限公司","organizationCode":"91330****73959654P","icpNo":"浙B2-20****01-4","icpPicOssKey":"db7784d8-cb0c-498f-****-295f1ad6d665_mf29l7nf.png", "companyDifferentFromSignQuaReason":"这是一段说明文字"},{"trafficDrivingType":"1_PHONE","trafficDrivingContent":"1**86","variableName":"my1Phone","companyName":"阿里云计算有限公司","organizationCode":"91330****73959654P","companyDifferentFromSignQuaReason":"这是一段说明文字"}]

Response elements

Element

Type

Description

Example

object

RequestId

string

The ID of the request. Alibaba Cloud generates a unique ID for each request. You can use this ID to troubleshoot issues.

F655A8D5-B967-440B-8683-DAD6FF8DE991

Code

string

The status code of the request. Valid values:

  • OK: The request was successful.

  • For other error codes, see the Error codes list in this topic or API Error Codes.

OK

Message

string

The description of the status code.

successful

TemplateName

string

The name of the message template.

验证码模板

TemplateCode

string

The code of the message template.

After you submit a template application, you can use the template code to call the GetSmsTemplate operation and query the review details of the template. You can also configure delivery receipts to receive the review status of the template in the TemplateSmsReport message.

SMS_10000****

OrderId

string

The ticket ID.

Reviewers use this ID to check the review status. You must provide this ID when you request an expedited review.

2005020****

Examples

Success response

JSON format

{
  "RequestId": "F655A8D5-B967-440B-8683-DAD6FF8DE991",
  "Code": "OK",
  "Message": "successful",
  "TemplateName": "验证码模板",
  "TemplateCode": "SMS_10000****",
  "OrderId": "2005020****"
}

Error codes

HTTP status code

Error code

Error message

Description

400 ForbiddenAction Access to the account is denied. Please contact the administrator.
400 AssocSignUnapproved Associated signature must be approved. The associated signature needs to use the approved signature.
400 InvalidTemplateRule.Format The parameter TemplateRule format must be JSON. Template variable rules must be filled with JSON-formatted data.
400 InvalidMoreData Specified parameter MoreData is not valid. The uploaded more information is invalid.
400 TemplateVarLimitExceeded The verification code template only supports one variable. The verification code template only supports one variable.
400 InvalidTemplateContent.Format Invalid template content format. The template content is not in the correct format.
400 InvalidTemplateRule The template variable format is non-standard. Please refer to the variable format specifications in the help documentation. The template variable does not meet the specifications. Please check the SMS template specification document and pass in the template variable that meets the requirements.
400 ServiceNotOpened This product service is not opened. Product service not activated
404 MissingTemplateName The template name cannot be empty. Template name cannot be empty.
404 SmsSignatureNotFound The associated SMS signature does not exist. The associated SMS signature does not exist.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.