Updated on 2024-03-13 GMT+08:00

Creating a Message Template

Function

This API is used to create a message template for quick message sending and reduced request data volume. By default, a user can create a maximum of 100 message templates. However, in rare high-concurrency scenarios, extra templates may be successfully created.

Calling Method

For details, see Calling APIs.

URI

POST /v2/{project_id}/notifications/message_template

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Specifies the project ID.For details about how to obtain the project ID, see Obtaining the Project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Specifies a user token.

It can be obtained by calling an IAM API. The value of X-Subject-Token in the response header is the user token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

message_template_name

Yes

String

Specifies the template name. Enter 1 to 64 characters, and start with a letter or digit. Only letters, digits, hyphens (-), and underscores (_) are allowed.

protocol

Yes

String

Specifies the protocol supported by the template.

The following protocols are supported:

default

email

sms

functionstage

dms

http and https

content

Yes

String

Specifies the template content, which supports plain text only. The template content cannot be left blank or larger than 256 KB.

Response Parameters

Status code: 201

Table 4 Response body parameters

Parameter

Type

Description

request_id

String

Specifies the request ID, which is unique.

message_template_id

String

Specifies the resource identifier of the template, which is unique.

Status code: 400

Table 5 Response body parameters

Parameter

Type

Description

request_id

String

Specifies the request ID, which is unique.

code

String

Specifies the error code.

message

String

Describes the error message.

Status code: 403

Table 6 Response body parameters

Parameter

Type

Description

request_id

String

Specifies the request ID, which is unique.

code

String

Specifies the error code.

message

String

Describes the error message.

Status code: 404

Table 7 Response body parameters

Parameter

Type

Description

request_id

String

Specifies the request ID, which is unique.

code

String

Specifies the error code.

message

String

Describes the error message.

Status code: 500

Table 8 Response body parameters

Parameter

Type

Description

request_id

String

Specifies the request ID, which is unique.

code

String

Specifies the error code.

message

String

Describes the error message.

Example Requests

Creating an HTTPS message template with the name of confirm_message

POST https://{SMN_Endpoint}/v2/{project_id}/notifications/message_template

{
  "message_template_name" : "confirm_message",
  "protocol" : "https",
  "content" : "(1/2)You are invited to subscribe to topic({topic_id}). Click the following URL to confirm subscription:(If you do not want to subscribe to this topic, ignore this message.)"
}

Example Responses

Status code: 201

OK

{
  "request_id" : "6a63a18b8bab40ffb71ebd9cb80d0085",
  "message_template_id" : "57ba8dcecda844878c5dd5815b65d10f"
}

Status Codes

Status Code

Description

201

OK

400

Bad Request

403

Unauthorized

404

Not Found

500

Internal Server Error

Error Codes

See Error Codes.