Querying Resources Using Tags
Function
This API is used to query resources using tags.
Calling Method
For details, see Calling APIs.
URI
POST /v2/{project_id}/{resource_type}/resource_instances/action
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Project ID. |
resource_type |
Yes |
String |
Resource type. The value can be DNS-public_zone, DNS-private_zone, DNS-public_recordset, DNS-private_recordset, or DNS-ptr_record. |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
Definition The user token. The token can be obtained by calling an IAM API. The value of X-Subject-Token in the response header is the user token. For details about how to obtain a user token, seeObtaining a User Token. Constraints N/A Range N/A Default Value N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
tags |
No |
Array of tagValues objects |
Tags that are included. A maximum of 10 tag keys are allowed. The structure body is mandatory. Each tag key must be unique and cannot be left blank or set to an empty string. A tag key can have up to 10 tag values, and each tag value in a tag must be unique. |
tags_any |
No |
Array of tagValues objects |
A maximum of 10 tag keys are allowed. The structure body is mandatory. Each tag key must be unique and cannot be left blank or set to an empty string. A tag key can have up to 10 tag values, and each tag value in a tag must be unique. |
not_tags |
No |
Array of tagValues objects |
A maximum of 10 tag keys are allowed. The structure body is mandatory. Each tag key must be unique and cannot be left blank or set to an empty string. A tag key can have up to 10 tag values, and each tag value in a tag must be unique. |
not_tags_any |
No |
Array of tagValues objects |
A maximum of 10 tag keys are allowed. The structure body is mandatory. Each tag key must be unique and cannot be left blank or set to an empty string. A tag key can have up to 10 tag values, and each tag value in a tag must be unique. |
limit |
No |
Integer |
The number of records returned on each page during pagination query. Range: 1 to 1000. If action is set to filter, the default value is 1000. If action is set to count, this parameter is not required. |
offset |
No |
Integer |
Start offset of the pagination query. The query will start from the next resource of the offset value. The value ranges from 0 to 2147483647, and the default value is 0. This parameter is not required when data on the first page is queried. When you query resources on subsequent pages, set the value of offset to the location returned in the response body for the previous query. If action is set to filter, the default value is 0. The value must be a number and cannot be a negative number. If action is set to count, this parameter does not exist. |
action |
Yes |
String |
Operation to be performed. The value options are case sensitive. Value options:
|
matches |
No |
Array of match objects |
This parameter specifies the key-value pair to be matched in the query. If value is left blank, exact search will work. Otherwise, fuzzy search will work. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
key |
No |
String |
Key. It can contain a maximum of 128 Unicode characters. The tag key cannot be left blank. (This parameter is not verified in the search process.) |
values |
No |
Array of strings |
Value list. Each value can contain a maximum of 255 Unicode characters. An asterisk (*) is a reserved character. If the value starts with an asterisk, fuzzy matching will work for the string following the asterisk. If this parameter is not specified, any value is matched. All values are in the OR relationship. |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
resources |
Array of resourceItem objects |
Resource tag list. |
total_count |
Integer |
List of tags added to a resource. |
Parameter |
Type |
Description |
---|---|---|
resource_id |
String |
Resource ID. |
resource_detail |
Object |
Resource details. This field is reserved, and its value defaults to an empty string. |
tags |
Array of tag objects |
Tag list. If there is no tag in the list, an empty array is returned. |
resource_name |
String |
Resource name. If no resource name is matched, this parameter is left blank. |
Parameter |
Type |
Description |
---|---|---|
key |
String |
Definition The tag key. Range
|
value |
String |
Definition The tag value. Range
|
Example Requests
Querying resources by tag, with the start offset of pagination query set to 100, and the number of resources displayed on each page to 100
POST https://{endpoint}/v2/{project_id}/{resource_type}/resource_instances/action { "offset" : "100", "limit" : "100", "action" : "filter", "matches" : [ { "key" : "resource_name", "value" : "resource1" } ], "not_tags" : [ { "key" : "key1", "values" : [ "*value1", "value2" ] } ], "tags" : [ { "key" : "key1", "values" : [ "*value1", "value2" ] } ], "tags_any" : [ { "key" : "key1", "values" : [ "value1", "value2" ] } ], "not_tags_any" : [ { "key" : "key1", "values" : [ "value1", "value2" ] } ] }
Example Responses
Status code: 200
Response to the request for querying resources by tag
{ "resources" : [ { "resource_detail" : null, "resource_id" : "cdfs_cefs_wesas_12_dsad", "resource_name" : "resource1", "tags" : [ { "key" : "key1", "value" : "value1" }, { "key" : "key2", "value" : "value1" } ] } ], "total_count" : 1000 }
Status Codes
Status Code |
Description |
---|---|
200 |
Response to the request for querying resources by tag |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.