Querying the Number of Resource Instances by Tag
Function
This API is used to query the number of resource instances by tag.
URI
POST /v1/{project_id}/{resource_type}/resource-instances/count
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Project ID |
resource_type |
Yes |
String |
Resource type.Default usage: auditInstance |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
Content-type |
Yes |
String |
The fixed value of this parameter is application/json;charset=UTF-8, which cannot be changed. |
X-Auth-Token |
Yes |
String |
User token |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
matches |
No |
Array of matches objects |
Specifies the search field. The tag key is the field to be matched, for example, resource_name. The tag value indicates the value to be matched. The key is a fixed dictionary value and cannot be a duplicate key or unsupported key. Check whether fuzzy match is required based on the key value. For example, if key is set to resource_name, fuzzy search (case-insensitive) is performed by default. If value is empty, exact match is performed. Most services do not have resources without names. In this case, an empty list is returned. If key is resource_id, exact match is used. Only resource_name for key is supported. Other key values will be available later. |
not_tags |
No |
Array of TagKeyValuesBean objects |
Tags are excluded, a maximum of 50 tag keys are included, and each tag value can have a maximum of 10 values. Each tag value can be an empty array, but the tag structure cannot be missing. Keys must be unique and values of a key must be unique. The response returns instances containing no tag in this list. Keys are in the AND relationship and values in each key-value structure is in the OR relationship. If no filtering condition is specified, full data is returned. |
tags |
No |
Array of TagKeyValuesBean objects |
The resources to be queried contain tags listed in tags. Each instance to be queried contains a maximum of 50 keys. Each tag key has a maximum of 10 tag values. The tag value corresponding to each tag key can be an empty array but the structure cannot be missing. Each tag key and each value of the same tag key must be unique. The response returns instances containing all tags in this list. Keys in this list are in the AND relationship and values in each key-value structure are in the OR relationship. If no tag filtering criteria is specified, full data is returned. |
tags_any |
No |
Array of TagKeyValuesBean objects |
Any tags are included. A maximum of 50 tag keys are included, and each tag key can have a maximum of 10 values. Each tag value can be an empty array, but the tag structure cannot be missing. Keys must be unique and values of a key must be unique. The response returns instances containing any tag in this list. Keys in this list are in the OR relationship and values in each key-value structure are also in the OR relationship. If no filtering condition is specified, full data is returned. |
not_tags_any |
No |
Array of TagKeyValuesBean objects |
Tags are excluded, a maximum of 50 tag keys are included, and each tag key can have a maximum of 10 values. Each tag value can be an empty array, but the tag structure cannot be missing. Keys must be unique and values of a key must be unique. The response returns resources containing no tag in this list. Keys in this list are in the OR relationship and values in each key-value structure are also in the OR relationship. If no filtering condition is specified, full data is returned. |
without_any_tag |
No |
Boolean |
If this parameter is set to true, all resources without tags are queried. In this case, the tags, tags_any, not_tags, and not_tags_any fields are ignored. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
key |
Yes |
String |
Specifies the tag key. It can contain up to 128 Unicode characters. It cannot be left blank. The system does not verify the character set of key when searching for resources. key cannot be empty, an empty string, or spaces. Before using key, delete single-byte character (SBC) spaces before and after the value. |
values |
Yes |
Array of strings |
Specifies the tag values. Each value contains a maximum of 255 Unicode characters. Before verifying and using values, delete SBC spaces before and after the value.The tag value can be an empty array but cannot be left blank.If values is left blank, it indicates any_value (querying any value). All values of a tag key are in the OR relationship. |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
resources |
Array of resources objects |
Resource instance list |
total_count |
Integer |
Total number of records. |
Parameter |
Type |
Description |
---|---|---|
resource_detail |
Object |
Resource details. Resource details are used for extension. This parameter is left blank by default. |
resource_id |
String |
Resource ID (DBSS instances ID, the instance ID is not in the basic information.) This parameter can be obtained through the interface : GET /v1/{project_id}/dbss/audit/instances |
resource_name |
String |
Specifies the resource name. If the resource does not have a name, the ID is returned. |
tags |
Array of tags objects |
The tag list. This parameter is an empty array by default if there is no tag. |
Parameter |
Type |
Description |
---|---|---|
key |
String |
Key |
value |
String |
Value |
Status code: 400
Parameter |
Type |
Description |
---|---|---|
error |
Object |
Error message. |
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error information. |
Status code: 403
Parameter |
Type |
Description |
---|---|---|
error |
Object |
Error message. |
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error information. |
Status code: 500
Parameter |
Type |
Description |
---|---|---|
error |
Object |
Error message. |
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error information. |
Example Requests
/v1/{project_id}/{resource_type}/resource-instances/count { "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
Success
{ "total_count" : 1000 }
Status code: 400
Failure
{ "error" : { "error_code" : "DBSS.XXXX", "error_msg" : "XXX" } }
Status Codes
Status Code |
Description |
---|---|
200 |
Success |
400 |
Failure |
403 |
Authentication failed. |
500 |
Server error. |
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.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot