GetMqttTicket

Updated at:

Retrieves the authentication credentials, access endpoints, and topic list required for a client to establish an MQTT connection.

Operation description

Call this operation to retrieve the credentials and connection information required for a client to establish an MQTT connection.

  1. Use MqttUsername and MqttPassword as the username and password when connecting the MQTT client.

  2. Use MqttEndpoint as the connection endpoint. If the client meets the required VPC network access conditions, you can use MqttVPCEndpoint. MqttInstanceId is used for token authentication, and MqttGroupId is used to concatenate the MQTT ClientId.

  3. Distinguish between publish and subscribe topics based on the topic, type, and permission fields of each item in TopicList. W indicates publish permission, and R indicates subscribe permission.

  4. ExpireTimeStamp is the UNIX timestamp in milliseconds when the password expires. Credentials may be reused. Retrieve new credentials based on the expiration time returned in the response.

The device identity and request IDs in the documentation are demo data. The domain name uses the example.com sample domain. Credentials and instance identity are sample or desensitized values. These examples cannot be used directly for actual connections.

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

appstreaming:GetMqttTicket

get

*All Resource

*

None None

Request parameters

Parameter

Type

Required

Description

Example

Uuid

string

Yes

The UUID of the device.

550e8400-e29b-41d4-a716-446655440000

ClientType

integer

Yes

The client type. Valid values: 0: hardware terminal; 1: Windows software terminal; 2: macOS software terminal; 3: iOS client; 4: Android client; 5: web client; 6: tenant console.

1

ClientOS

string

Yes

The operating system of the client.

Windows 10

ClientVersion

string

Yes

The version number of the client.

1.0.0

Properties

object

No

The extended properties of the client, represented as a JSON object where both keys and values are strings. Example: {"a":"1","b":"2"}. If this parameter is not specified, an empty property set is used.

{"a":"1","b":"2"}

Response elements

Element

Type

Description

Example

object

Schema of Response

RequestId

string

The request ID.

B9E3F7B2-5B13-4A7B-8C36-6D1B0A8F0000

MqttUsername

string

The username used to establish an MQTT connection. The format is Token|AccessKeyId|InstanceId. AccessKeyId and InstanceId are identifiers used by the server to generate credentials. Use the complete username returned in the response.

Token|LTAI5tExample****|post-cn-7mz2****

MqttPassword

string

The password used to establish an MQTT connection. It consists of publish and subscribe tokens in the format of W|PublishToken|R|SubscribeToken. Use the complete password returned in the response. The desensitized examples in the documentation cannot be used for connections.

W|pubTokenExample****|R|subTokenExample****

ExpireTimeStamp

string

The expiration time of the MQTT connection password. It is a UNIX timestamp in milliseconds and is returned as a string.

1794278400000

MqttEndpoint

string

The access endpoint for the MQTT client. Use the endpoint returned in this response to establish a connection.

mqtt.example.com

MqttVPCEndpoint

string

The VPC access endpoint for MQTT. It is used by clients that meet the required VPC network access conditions.

mqtt-vpc.example.com

MqttInstanceId

string

The ID of the MQTT instance, used for token authentication.

post-cn-7mz2****

MqttGroupId

string

The MQTT group ID, used to concatenate the MQTT ClientId.

GID_EXAMPLE

Code

string

The error code returned when the request fails. For example, Client.Forbidden indicates that the client is forbidden from establishing a connection.

Client.Forbidden

Message

string

The error message returned when the request fails. It corresponds to the error code.

Client forbidden connect

Success

string

Indicates whether the request is successful. A value of true indicates success, and a value of false indicates failure.

true

TopicList

string

The topic list. Each element in the list contains topic (the topic name), type (the topic type), and permission (the permission). The list returned by this operation includes topics for publishing, tenant subscription, device subscription, and system subscription. The publish permission is W, and the subscribe permission is R.

[{"topic":"pub/550e8400-e29b-41d4-a716-446655440000","type":"pub","permission":"W"},{"topic":"sub/ten/123456789012****","type":"sub-ten","permission":"R"},{"topic":"sub/uuid/550e8400-e29b-41d4-a716-446655440000","type":"sub-uuid","permission":"R"},{"topic":"sub/sys","type":"sub-sys","permission":"R"}]

The examples for MqttUsername, MqttPassword, the connection endpoint, and TopicList demonstrate the field formats when credentials are successfully retrieved. The actual values are subject to the response.

The examples for Code and Message demonstrate a failure scenario where the client is forbidden from connecting: Code is Client.Forbidden, Message is Client forbidden connect, and Success is false. These error field examples do not belong to the same response as the credential examples in the success scenario.

The type field in TopicList is used to distinguish the purpose of the topic. For example, pub indicates a publish topic, sub-ten indicates a tenant subscription topic, sub-uuid indicates a device subscription topic, and sub-sys indicates a system subscription topic.

Examples

Success response

JSON format

{
  "RequestId": "B9E3F7B2-5B13-4A7B-8C36-6D1B0A8F0000",
  "MqttUsername": "Token|LTAI5tExample****|post-cn-7mz2****",
  "MqttPassword": "W|pubTokenExample****|R|subTokenExample****",
  "ExpireTimeStamp": "1794278400000",
  "MqttEndpoint": "mqtt.example.com",
  "MqttVPCEndpoint": "mqtt-vpc.example.com",
  "MqttInstanceId": "post-cn-7mz2****",
  "MqttGroupId": "GID_EXAMPLE",
  "Code": "Client.Forbidden",
  "Message": "Client forbidden connect",
  "Success": "true",
  "TopicList": "[{\"topic\":\"pub/550e8400-e29b-41d4-a716-446655440000\",\"type\":\"pub\",\"permission\":\"W\"},{\"topic\":\"sub/ten/123456789012****\",\"type\":\"sub-ten\",\"permission\":\"R\"},{\"topic\":\"sub/uuid/550e8400-e29b-41d4-a716-446655440000\",\"type\":\"sub-uuid\",\"permission\":\"R\"},{\"topic\":\"sub/sys\",\"type\":\"sub-sys\",\"permission\":\"R\"}]"
}

Error codes

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.