Queries a list of tags that are attached to one or more instances.

API description

  • To determine the search object, a request should include the parameter ResourceId.N or Tag.N (that is, Tag.N.Key and Tag.N.Value).
  • Tag.N is a resource tag and consists of a key-value pair. When only Tag.N.Key is specified, all tag values associated with the tag key are returned. When only Tag.N.Value is specified, an error is reported.
  • If you specify Tag.N and ResourceId.N simultaneously, ResourceId.N must match all the tag key-value inputs.
  • If you specify multiple tag key-value pairs at the same time, the returned results are the resources that contain the specified multiple key-value pairs.

Make the API call

You can use OpenAPI Explorer to make API calls, search for API calls, perform debugging, and generate SDK example code.

Request parameters

Parameter Type Required? Example value Description
Action String Yes ListTagResources

The name of this action. Valid value: ListTagResources

RegionId String Yes cn-hangzhou

The ID of the region to which the resource belongs.

ResourceType String Yes VPC

The type of the resource. Valid values:

  • VPC: Virtual Private Cloud (VPC)
  • VSWITCH: VSwitch
  • ROUTETABLE: Route table
  • EIP: Elastic IP address
ResourceId.N RepeatList No vpc-bp16qjewdsunr41m1****

The ID of the resource. Value range of N: 1 to 20.

Tag.N.Key String No FinanceDept

The tag key of the resource. Value range of N: 1 to 20. This value cannot be a null string. It can be up to 64 characters in length and can contain numbers, periods (.), underscores (_), and hyphens (-). It must start with a letter and cannot start with aliyun or acs:. It cannot contain http:// or https://.

Tag.N.Value String No FinanceJoshua

The tag value of the resource. Value range of N: 1 to 20. This value can be a null string. It can be up to 128 characters in length and can contain letters, numbers, periods (.), underscores (_), and hyphens (-). It must start with a letter and cannot start with aliyun or acs:. It cannot contain http:// or https://.

NextToken String No caeba0bbb2be03f84eb48b699f0a4883

The query Token. The value of this parameter is the value of the NextToken parameter returned in the last API call. If no next query exists, skip this step.

Response parameters

Parameter Type Example value Description
RequestId String DE65F6B7-7566-4802-9007-96F2494AC512

The ID of the request.

NextToken String caeba0bbb2be03f84eb48b699f0a4883

The start Token of the next query. If NextToken is null, there is no next Token.

TagResources Array

The information of queried instances and tags.

TagKey String FinanceDept

The tag key.

TagValue String FinanceJoshua

The tag value.

ResourcId String vpc-bp16qjewdsunr41m1****

The ID of the resource.

ResourceType String VPC

The type of the resource.

Examples

Request example

http(s)://[Endpoint]/? Action=ListTagResources
&RegionId=cn-hangzhou
&ResourceType=VPC
&ResourceId.1=vpc-bp16qjewdsunr41m1****
&<CommonParameters>

Response example

XML format

<ListTagResourcesResponse>
  <TagResources>
        <TagResource>
              <ResourceType>VPC</ResourceType>
              <TagValue>aa</TagValue>
              <TagKey>aaa</TagKey>
              <ResourcId>vpc-wz9aml8mptq6fsnfmfv23</ResourcId>
        </TagResource>
  </TagResources>
  <NextToken></NextToken>
  <RequestId>F11AC96F-B8E6-48F8-95CC-F63E7D50F0D4</RequestId>
</ListTagResourcesResponse>

JSON format

{
	"TagResources": {
		"TagResource": [
			{
				"ResourceType": "VPC",
				"TagValue": "aa",
				"TagKey": "aaa",
				"ResourcId": "vpc-wz9aml8mptq6fsnfmfv23"
			}
		]
	},
	"NextToken": "",
	"RequestId": "F11AC96F-B8E6-48F8-95CC-F63E7D50F0D4"
}

Errors

HTTP status code Error code Error message Description
403 Forbidden User not authorized to operate on the specified resource. You are not authorized to operate on this resource.

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