ApplyToken

更新时间: 2026-01-20 11:49:42

Call the ApplyToken operation to create a temporary access token.

Scenarios

The application server must initiate the API call to request a token. After the application server verifies the permission scope of the ApsaraMQ for MQTT client, it requests a token from the ApsaraMQ for MQTT server on behalf of the client. For more information, see Token-based authentication.

Limits

The request frequency is limited to 500 calls per second for each user. If you have special requirements, you can submit a ticket.

Debug

You can call this operation in OpenAPI Explorer. This eliminates the need to calculate signatures. Upon successful execution, OpenAPI Explorer automatically generates SDK code examples.

Request parameters

NameTypeRequiredExampleDescription
ActionStringYesApplyToken

A required parameter. Set the value to ApplyToken.

ActionsStringYesR

The permission type of the token. Valid values:

  • R: Read-only.
  • W: Write-only.
  • R,W: Read and write. Separate R and W with a comma (,).
ExpireTimeLongYes1578399620000

The UNIX timestamp in milliseconds when the token expires. The minimum validity period is 60 seconds and the maximum is 30 days. If you specify a validity period longer than 30 days, the API call does not return an error, but the token is valid for only 30 days.

InstanceIdStringYespost-cn-0pp12gl****

The ID of the ApsaraMQ for MQTT instance. This must match the ID of the instance that the client uses. Obtain this ID from the Instance Details page in the console.

RegionIdStringYesmq-internet-access

The region where the ApsaraMQ for MQTT instance resides.

ResourcesStringYesTopicA/+

The name of the resource, which is an MQTT topic. To specify multiple topics, separate them with commas (,). Each token can be used for operations on a maximum of 100 resources. If you specify multiple topics, sort them in alphabetical order.

The resource parameter supports MQTT wildcard syntax, including the single-level wildcard character (+) and the multi-level wildcard character (#).

For example, if you set resources to "Topic1/+", the client can operate on any topic that is a direct child of "Topic1". If you set resources to "Topic1/#", the client can operate on any topic in the "Topic1" hierarchy.

Note For more information, see Common parameters and Request syntax.

Returned data

NameTypeExampleDescription
RequestIdString31782AAF-D0CC-44C3-ABFD-1B500276F8CD

A common parameter. The unique ID of the request.

TokenStringLzMT+XLFl5s/YWJ/MlDz4t/Lq5HC1iGU1P28HAMaxYxn8aQbALNtml7QZKl9L9kPe6LqUb95tEVo+zUqOogs9+jZwDUSzsd4X4qaD3n2TrBEuMOqKkk1Xdrvu9VBQQvIYbz7MJWZDYC3DlW7gLEr33Cuj54iIhagtBi3epStJitsssWs7otY9zhKOSZxhr49G3d0bh35mwyP18EMvDas8UlzeSozsSrujNUqZXOGK0PEBSd+rWMGDJlCt6GFmJgm2JFY7PJwf/7OOSmUYIYFs5o/PuPpoTMF+hcVXMs+0yDukIMTOzG9m3t8k36PVrghFmnK6pC3Rt3mibjW****ng==

The token returned by the server.

Note Do not make any assumptions about the length, format, or rules of the returned token. Use the exact value that is returned.

Examples

Sample request

http(s)://onsmqtt.cn-hangzhou.aliyuncs.com/?Action=ApplyToken
&Actions=R
&ExpireTime=1578399620000
&InstanceId=post-cn-0pp12gl****
&RegionId=mq-internet-access
&Resources=TopicA/+
&<Common request parameters>

Sample success response

XML format

<RequestId>31782AAF-D0CC-44C3-ABFD-1B500276F8CD</RequestId>
<Token>LzMT+XLFl5s/YWJ/MlDz4t/Lq5HC1iGU1P28HAMaxYxn8aQbALNtml7QZKl9L9kPe6LqUb95tEVo+zUqOogs9+jZwDUSzsd4X4qaD3n2TrBEuMOqKkk1Xdrvu9VBQQvIYbz7MJWZDYC3DlW7gLEr33Cuj54iIhagtBi3epStJitsssWs7otY9zhKOSZxhr49G3d0bh35mwyP18EMvDas8UlzeSozsSrujNUqZXOGK0PEBSd+rWMGDJlCt6GFmJgm2JFY7PJwf/7OOSmUYIYFs5o/PuPpoTMF+hcVXMs+0yDukIMTOzG9m3t8k36PVrghFmnK6pC3Rt3mibjW****ng==</Token>

JSON format

{
  "RequestId": "31782AAF-D0CC-44C3-ABFD-1B500276F8CD",
  "Token": "LzMT+XLFl5s/YWJ/MlDz4t/Lq5HC1iGU1P28HAMaxYxn8aQbALNtml7QZKl9L9kPe6LqUb95tEVo+zUqOogs9+jZwDUSzsd4X4qaD3n2TrBEuMOqKkk1Xdrvu9VBQQvIYbz7MJWZDYC3DlW7gLEr33Cuj54iIhagtBi3epStJitsssWs7otY9zhKOSZxhr49G3d0bh35mwyP18EMvDas8UlzeSozsSrujNUqZXOGK0PEBSd+rWMGDJlCt6GFmJgm2JFY7PJwf/7OOSmUYIYFs5o/PuPpoTMF+hcVXMs+0yDukIMTOzG9m3t8k36PVrghFmnK6pC3Rt3mibjW****ng=="
}

Error codes

HTTP status codeError codeError messageDescription
404ApiNotSupportThe specified API is not supported.The API is not supported. Check your request.
400ApplyTokenOverFlowYou have applied for tokens too many times. Please try again later.The frequency of token requests is too high. The system is throttling the requests. Try again later.
400CheckAccountInfoFailedAn error occurred while checking the account information by the STS token.Failed to parse the account information from the Security Token Service (STS) token.
400InstancePermissionCheckFailedAn error occurred while validating the permissions of the instance. Please verify the account that created the instance and its permissions settings.Instance permission check failed. Confirm the ownership and authorization policy of the ApsaraMQ for MQTT instance.
500InternalErrorAn error occurred while processing your request. Try again later.An error occurred in the ApsaraMQ for MQTT backend service. Try again later.
400ParameterCheckFailedAn error occurred while validating the parameters. The parameters may be missing or invalid.Parameter verification failed. A parameter may be missing or invalid.
400PermissionCheckFailedAn error occurred while validating the resource permissions. Please check the account that created the instance, topic, and GroupId, and check their permission settings.Resource permission check failed. Check the ownership and authorization policies for the instance, topic, and group ID.
500SystemOverFlowAn error occurred while processing your request. Please try again.The system is throttling the requests. Try again later.
400InvalidParameter.%sAn error occurred while validating the parameter. The parameter may be missing or invalid.Parameter verification failed. A parameter may be missing or invalid.

For a list of additional error codes, visit the Error Center.

上一篇: Token application server API 下一篇: QueryToken