Queries the tag policies that are attached to an object.

Usage notes

If you use the Tag Policy feature in single-account mode, you can use the current logon account to call this API operation to query the tag policies that are attached to the account. If you use the Tag Policy feature in multi-account mode, you can use the management account of a resource directory to call this API operation to query the tag policies that are attached to the Root folder, a folder other than the Root folder, or a member in the resource directory. For more information about the modes of the Tag Policy feature, see Modes of the Tag Policy feature.

This topic provides an example on how to call the API operation to query the tag policies that are attached to the current logon account. In this example, the Tag Policy feature in single-account mode is used. The response shows that only one tag policy is attached to the current logon account.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes ListPoliciesForTarget

The operation that you want to perform. Set the value to ListPoliciesForTarget.

RegionId String No cn-shanghai

The region ID. Set the value to cn-shanghai.

MaxResult Integer No 50

The number of entries to return on each page.

Default value: 50. Maximum value: 1000.

NextToken String No caeba0bbb2be03f84eb48b699f0a****

The token that is used to start the next query.

TargetId String No 154950938137****

The ID of the object. This parameter specifies a filter condition for the query.

TargetType String No ACCOUNT

The type of the object. This parameter specifies a filter condition for the query. Valid values:

  • USER: the current logon account. This value is available if you use the Tag Policy feature in single-account mode.
  • ROOT: the Root folder in a resource directory. This value is available if you use the Tag Policy feature in multi-account mode.
  • FOLDER: a folder other than the Root folder in a resource directory. This value is available if you use the Tag Policy feature in multi-account mode.
  • ACCOUNT: a member in a resource directory. This value is available if you use the Tag Policy feature in multi-account mode.
Note The value of this parameter is not case-sensitive.

For more information about common request parameters, see Common parameters.

Response parameters

Parameter Type Example Description
Data Array of Data

The tag policies that are attached to the object.

PolicyId String p-de62a0bf400e4b69****

The ID of the tag policy.

PolicyName String example

The name of the tag policy.

PolicyDesc String This is a tag policy example.

The description of the tag policy.

PolicyContent String {\"tags\":{\"CostCenter\":{\"tag_value\":{\"@@assign\":[\"Beijing\",\"Shanghai\"]},\"tag_key\":{\"@@assign\":\"CostCenter\"}}}}

The document of the tag policy.

UserType String USER

The mode of the Tag Policy feature. Valid values:

  • USER: single-account mode
  • RD: multi-account mode

For more information about the modes of the Tag Policy feature, see Modes of the Tag Policy feature.

RequestId String 8C962146-AB38-516C-818C-695D4E9F2EA2

The ID of the request.

NextToken String caeba0bbb2be03f84eb48b699f0a****

Indicates whether the next query is required.

  • If the value of this parameter is empty ("NextToken": ""), all results are returned, and the next query is not required.
  • If the value of this parameter is not empty, the next query is required, and the value is the token used to start the next query.

Examples

Sample requests

https://tag.aliyuncs.com/?Action=ListPoliciesForTarget
&RegionId=cn-shanghai
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<ListPoliciesForTargetResponse>
    <RequestId>8C962146-AB38-516C-818C-695D4E9F2EA2</RequestId>
    <Data>
        <PolicyDesc>This is a tag policy example.</PolicyDesc>
        <PolicyName>example</PolicyName>
        <UserType>USER</UserType>
        <PolicyId>p-de62a0bf400e4b69****</PolicyId>
        <PolicyContent>{"tags":{"CostCenter":{"tag_value":{"@@assign":["Beijing","Shanghai"]},"tag_key":{"@@assign":"CostCenter"}}}}</PolicyContent>
    </Data>
</ListPoliciesForTargetResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "8C962146-AB38-516C-818C-695D4E9F2EA2",
  "Data" : [ {
    "PolicyDesc" : "This is a tag policy example.",
    "PolicyName" : "example",
    "UserType" : "USER",
    "PolicyId" : "p-de62a0bf400e4b69****",
    "PolicyContent" : "{\"tags\":{\"CostCenter\":{\"tag_value\":{\"@@assign\":[\"Beijing\",\"Shanghai\"]},\"tag_key\":{\"@@assign\":\"CostCenter\"}}}}"
  } ]
}

Error codes

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