All Products
Search
Document Center

ApsaraVideo Live:CreateEventSub

Dernière mise à jour :Jul 15, 2026

Creates a callback for subscribing to channel messages.

Operation description

Creates a callback for subscribing to channel messages. For example, when creating a callback, you can configure parameters such as the callback URL and event types.

QPS limit

The single-user QPS limit for this operation is 100 calls per second. If the limit is exceeded, API calls are throttled, which may affect your business. Call this operation appropriately.

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

live:CreateEventSub

none

*Rtc

acs:live::{#accountId}:rtc/{#AppId}

None None

Request parameters

Parameter

Type

Required

Description

Example

AppId

string

Yes

The ID of the application to subscribe to. You can view your application IDs by navigating to ApsaraVideo Live > Live+ > ApsaraVideo Real-time Communication > Application Management. If no application exists, create one by clicking [Create Application].

9qb1****

ChannelId

string

No

The ID of the channel to subscribe to. You can call the ListEventSub operation to query the subscribed channel IDs.

Note
  • If the Users.N parameter is not empty, this parameter is required.

  • If ChannelId is set to * or left empty, all channels are subscribed. Each AppId allows only one all-channel subscription.

  • Each AppId allows a maximum of 20 subscriptions at the same time.

123333

Users

array

No

The users whose messages you want to subscribe to. If this parameter is empty, all users in the channel (including streamers and viewers) are subscribed. Format:

Users.1=****
Users.2=****
......

string

No

The user ID.

user1

Events

array

Yes

The subscription events.

string

Yes

The subscription event. Valid values:

  • ChannelEvent: channel event.

  • UserEvent: user event within a channel.

ChannelEvent

CallbackUrl

string

Yes

The callback URL. For the callback content, see the callback content examples below.

http://****.com/callback

Callback

The following example shows the content that is called back to the user through the specified CallbackUrl:

Request:

POST /callbackURL

Body
application/json

{
    "MsgId": "Message ID",
    "MsgTimestamp": 12312324, // Unix timestamp when the message is sent
    "SubscribeID": "Subscription ID",
    "AppId":"",     // The AppId that generated this message 
    "ChannelID":"", // The channel that generated this message
    "Contents": [
      {
        "Event": "UserEvent",// Subscription event: user event within a channel
        "UserEvent": {
          "UserId": "80331631628*****",    // User ID
          "EventTag": "Publish",    // Event, including Join, Leave, Publish, Unpublish, Roleupdate
          "SessionId": "0dr15rrnhkz0jnvz6o8sxo0*****", // The SessionID that generated this event
          "Timestamp": 1609854786,    // Unix timestamp when the event occurred
          "Reason": 1, // Reason for joining or leaving. Only available for Join events.
          "Role": 1, //  Role type: streamer or viewer
          "CurrentMedias":"1,2,3"// Stream type: the streams published by the user
        }
      },
      {
        "Event": "ChannelEvent",// Subscription event: channel event
        "ChannelEvent": {
          "ChannelId": "88888****",
          "EventTag": "Open",   // Channel event, including Open and Close
          "Timestamp": 1609854530 // Unix timestamp when the event occurred
        }
      }
   ]
}

Response 
HTTP STATUS 200

UserEvent

ParameterTypeRequiredDescription
UserIdstringYesThe user ID.
SessionIdstringYesThe user session ID.
EventTagstringYesThe event type. Valid values:
Join: joins the channel.
Leave: leaves the channel.
PublishVideo: starts publishing a video stream.
PublishAudio: starts publishing an audio stream.
PublishScreen: starts screen sharing.
UnpublishVideo: stops publishing a video stream.
UnpublishAudio: stops publishing an audio stream.
UnpublishScreen: stops screen sharing.
Roleupdate: switches the role.
TimestampnumberYesThe timestamp when the event occurred.
ReasonintegerYesThe reason for joining or leaving (only available for Join events). Valid values:
1: normal join or leave.
2: reconnection join (the user already exists in the channel and joins again).
3: cross-channel relay.
4: timeout leave.
5: the user starts a new session and the current session is forced offline.
6: kicked out.
7: channel dismissed.
RoleintegerYesThe role type. Valid values:
1: streamer.
2: viewer.
CurrentMediasintegerYesThe stream type. Valid values:
1: audio.
2: video.
3: screen sharing.

ChannelEvent

ParameterTypeRequiredDescription
EventTagstringYesThe event type. Valid values:
Open: the meeting starts.
Close: the meeting ends.
TimestampnumberYesThe timestamp when the event occurred.

Callback authentication

The event callback authentication feature is enabled by default. The authentication logic is as follows:

  • When ApsaraVideo Live initiates a callback request, the HTTP(S) request header contains the Ali-Rtc-Timestamp and Ali-Rtc-Signature fields for the callback message receiving server to perform signature authentication. The Ali-Rtc-Timestamp value is calculated as follows: Ali-Rtc-Signature=MD5SUM(MD5CONTENT), where MD5CONTENT=Callback domain name|Ali-Rtc-Timestamp value|Authentication Key. The callback domain name is the domain name configured in the callback URL, and the authentication Key is the AppKey generated when the AppId was created.

  • When the callback message receiving server receives a callback message, it concatenates the callback domain name, Ali-Rtc-Timestamp value, and authentication Key, calculates the MD5 value to obtain an encrypted string, and then compares the calculated encrypted string with the Ali-Rtc-Signature field value in the HTTP(S) request header initiated by ApsaraVideo Real-time Communication. If they do not match, the request is invalid.

Callback exception retry

When Alibaba Cloud initiates a callback request, the callback is considered successful only when your business server responds with HTTP status code 200. If the callback fails, Alibaba Cloud retries 7 times at intervals of 1 second, 2 seconds, 5 seconds, 10 seconds, 1 minute, 2 minutes, and 5 minutes. Each retry generates a corresponding callback record.

Exception handling

Clients that have joined a channel or are publishing streams maintain a heartbeat keep-alive mechanism with the Alibaba Cloud server. When the heartbeat keep-alive fails because the client loses network connectivity or the app is closed abnormally (failure is determined if no heartbeat is received from the client for 90 seconds), the server determines that the client has timed out and left abnormally, and generates event callbacks for the user stopping stream publishing and leaving the channel.

Response elements

Element

Type

Description

Example

object

Schema of Response

RequestId

string

The request ID.

760bad53276431c499e30dc36f6b****

SubscribeId

string

The ID of the created subscription.

ad53276431c****

Examples

Success response

JSON format

{
  "RequestId": "760bad53276431c499e30dc36f6b****",
  "SubscribeId": "ad53276431c****"
}

Error codes

HTTP status code

Error code

Error message

Description

400 InputInvalid %s. Illegal input parameters
400 QuotaLimitError %s. For each AppId, a maximum of 20 subscriptions are allowed at the same time, and only one full channel subscription is allowed.
400 ErrorInvalidCallBackUrl %s. The CallBackURL is invalid, please check and try again.
500 ServerError %s. Unknown error, please try again later or submit a ticket for consultation.
403 NoAuth %s. No permission
404 ResourceNotExist %s. The requested resource does not exist, please check and try again

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.