GetMqttTicket
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.
Use
MqttUsernameandMqttPasswordas the username and password when connecting the MQTT client.Use
MqttEndpointas the connection endpoint. If the client meets the required VPC network access conditions, you can useMqttVPCEndpoint.MqttInstanceIdis used for token authentication, andMqttGroupIdis used to concatenate the MQTT ClientId.Distinguish between publish and subscribe topics based on the
topic,type, andpermissionfields of each item inTopicList.Windicates publish permission, andRindicates subscribe permission.ExpireTimeStampis 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
Test
RAM authorization
|
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"} |
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|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|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 |
| 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 |
| TopicList |
string |
The topic list. Each element in the list contains |
[{"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.