Subscribe

Updated at:

Creates a subscription for a topic.

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

mns:Subscribe

update

*Subscription

acs:mns:{#regionId}:{#accountId}:/topics/{#TopicName}/subscriptions/{#SubscriptionName}

  • mns:PushType
None

Request parameters

Parameter

Type

Required

Description

Example

TopicName

string

Yes

The name of the topic. The name must be 1 to 255 characters in length. It must start with a letter or a digit, and can contain only letters, digits, and hyphens (-). The name cannot start with mns-reserved-.

topic****1

SubscriptionName

string

Yes

The name of the subscription. The name must be 1 to 255 characters in length. It must start with a letter or a digit, and can contain only letters, digits, and hyphens (-). The name cannot start with mns-reserved-.

testSubscription

PushType

string

Yes

Push types for subscriptions

Valid values:

  • http: Pushes messages to the specified HTTP or HTTPS callback URL.

  • queue: Pushes messages to the specified Simple Message Queue (SMQ) queue.

  • dm: Sends notifications by using the Direct Mail service. You must also set the DmAttributes and StsRoleArn parameters.

  • dysms: Sends notifications by using the Alibaba Cloud SMS service. You must also set the DysmsAttributes parameter.

  • fc: Pushes messages to Alibaba Cloud Function Compute (FC).

  • eventbus: Pushes messages to an EventBridge event bus.

Note: The following values are deprecated and are retained only for compatibility with legacy subscriptions:

  • mpush: mobile push

  • alisms: legacy SMS

  • email: legacy email, use dm instead

  • kafka: deprecated Kafka push type

queue

Endpoint

string

Yes

Endpoint for receiving messages

The format varies based on the PushType parameter:

  • PushType=http: The HTTP or HTTPS callback URL, such as http://example.com/callback or https://example.com/callback.

  • PushType=queue: The ARN of the destination queue, in the format of acs:mns:{RegionId}:{Alibaba Cloud account ID}:/queues/{QueueName}.

  • PushType=dm: The Direct Mail push endpoint, in the fixed format of smq-ep:dm:{Alibaba Cloud account ID}:__dynamic. Replace {Alibaba Cloud account ID} with the ID of your Alibaba Cloud account.

  • PushType=dysms: The SMS push endpoint, in the format of smq-ep:dysms:{Alibaba Cloud account ID}:{Phone number}.

  • PushType=kafka: The Kafka push endpoint. The Kafka push type is deprecated.

  • PushType=fc: The Function Compute endpoint, in the format of acs:fc:{RegionId}:{Alibaba Cloud account ID}:services/{ServiceName}/functions/{FunctionName}.

  • PushType=eventbus: The EventBridge endpoint, in the format of acs:eventbridge:{RegionId}:{Alibaba Cloud account ID}:eventbus/{EventBusName}.

http://*****.com/uri1/xxx

NotifyStrategy

string

No

The retry strategy that is used when an error occurs during message pushing to the endpoint. Valid values:

  • BACKOFF_RETRY: backoff retry (default)

  • EXPONENTIAL_DECAY_RETRY: exponential decay retry

BACKOFF_RETRY

NotifyContentFormat

string

No

Format of the pushed message content

Valid values:

  • XML: XML format (default)

  • JSON: JSON format

  • SIMPLIFIED: original message body content without the SMQ metadata wrapper

XML

MessageTag

string

No

The tag used for message filtering in the subscription. Only messages with a matching tag are pushed. The value must be a string up to 16 characters in length.

By default, message filtering is not performed.

important

DlqPolicy

object

No

The dead-letter queue policy.

Enabled

boolean

No

Specifies whether to enable dead-letter message delivery. Default value: false.

true

DeadLetterTargetQueue

string

No

The destination queue for dead-letter message delivery. The queue must already exist in the current region.

deadLetterTargetQueue

TenantRateLimitPolicy

object

No

The throttling policy.

Enabled

boolean

No

Specifies whether to enable the throttling policy. Valid values:

  • true: enabled

  • false: disabled (default)

MaxReceivesPerSecond

integer

No

The maximum number of pushes or consumptions per second. The value must be a positive integer and is valid only when the PushType parameter is set to http or https. The specific minimum value varies by region.

50

StsRoleArn

string

No

The ARN of the RAM role assumed by the service. The format is acs:ram::{Alibaba Cloud account ID}:role/{RoleName}. Replace {Alibaba Cloud account ID} with the ID of the Alibaba Cloud account that calls the API operation.

acs:ram::1234567890:role/AliyunMNSNotificationRole

DmAttributes

object

No

The attributes for Direct Mail push. This parameter is required when the PushType parameter is set to dm. The value is in JSON format and contains the following fields:

  • AccountName: the sender address, which is the sender address configured in Direct Mail, such as notify@example.com.

  • Subject: the email subject.

AccountName

string

No

The sender address.

notify@example.com

Subject

string

No

The email subject.

notify

DysmsAttributes

object

No

The attributes for SMS push. This parameter is required when the PushType parameter is set to alisms. The value is in JSON format and contains the following fields:

  • TemplateCode: the code of the SMS template, which can be obtained from the SMS console.

  • SignName: the name of the SMS signature.

TemplateCode

string

No

The code of the SMS template.

123456

SignName

string

No

The name of the SMS signature.

Alibaba Cloud SMS test

KafkaAttributes

object

No

The Kafka push type is deprecated.

BusinessMode

string

No

The Kafka push type is deprecated.

Default empty string

Response elements

Element

Type

Description

Example

object

RequestId

string

The ID of the request.

06273500-249F-5863-121D-74D51123****

Code

integer

The response code.

200

Status

string

The status of the response.

Success

Message

string

The response message.

operation success

Success

boolean

Indicates whether the request is successful.

true

Data

string

The response data.

{'Code': 200, 'Success': True}

Examples

Success response

JSON format

{
  "RequestId": "06273500-249F-5863-121D-74D51123****",
  "Code": 200,
  "Status": "Success",
  "Message": "operation success",
  "Success": true,
  "Data": "{'Code': 200, 'Success': True}"
}

Error codes

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.