Updated on 2025-10-29 GMT+08:00

Querying the Number of Resource Instances

Function

This API is used to query the number of resource instances by tag.

Calling Method

For details, see Calling APIs.

URI

POST /v1/{project_id}/{resource_type}/resource-instances/count

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

resource_type

Yes

String

Resource type.

project_id

Yes

String

Definition

Project ID, which is used to specify the project that a resource belongs to. You can query the resources of a project by project ID. You can obtain the project ID from the API or console. Obtaining the Project ID

Constraints

N/A

Range

N/A

Default Value

N/A

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

Content-type

Yes

String

Definition

Content type.

  • application/json;charset=UTF-8: common API request type

Constraints

N/A

Range

  • application/json;charset=UTF-8

Default Value

N/A

X-Auth-Token

Yes

String

User token.

You can call the IAM API to obtain a user token. The value of X-Subject-Token in the response header is the user token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

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 not required.

tags

No

Array of WorkspaceTag objects

Resources to be queried contain tags specified in this field. Each resource can contain a maximum of 50 keys. Each tag key can have 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 key must be unique, and each value for a 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 are specified, all data is returned.

sys_tags

No

Array of WorkspaceTag objects

Only users with the permission op_service can use this field to filter resources. Currently, TMS can invoke only one tag structure. Key: _sys_enterprise_project_id. Value: enterprise project ID list. Currently, TMS can invoke only one value under key. 0 indicates the default enterprise project. sys_tags cannot be used together with tenant tag filtering criteria (without_any_tag, tags, tags_any, not_tags, and not_tags_any). If sys_tags is not specified, resources with all the tags specified in tags will be returned. If tags is not specified, all resources will be returned.

matches

No

Array of Match objects

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. For search by resource_id, exact match is used. Only resource_name is supported currently. More fields will be supported later.

Table 4 WorkspaceTag

Parameter

Mandatory

Type

Description

key

Yes

String

Tag key. It can contain a maximum of 128 Unicode characters. The tag key 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

The tag value list. Each value can contain a maximum of 255 Unicode characters. Before verification and usage, delete SBC spaces before and after the value.

The value can be an empty array but cannot be left blank.

If values is left empty, it indicates any value. All values of a tag key are in the OR relationship.

Table 5 Match

Parameter

Mandatory

Type

Description

key

Yes

String

Key. Currently, only resource_name is supported. Other key values will be available later.

value

Yes

String

Value. Each value can contain a maximum of 255 Unicode characters. The character set is not verified.

Response Parameters

Status code: 200

Table 6 Response body parameters

Parameter

Type

Description

total_count

Integer

Total resources.

Status code: 400

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error description.

Status code: 401

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error description.

Status code: 403

Table 9 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error description.

Status code: 404

Table 10 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error description.

Status code: 500

Table 11 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error description.

Example Requests

{
  "not_tags" : [ {
    "key" : "key1",
    "values" : [ "value1", "*value2" ]
  } ],
  "tags" : [ {
    "key" : "key1",
    "values" : [ "value1", "value2" ]
  }, {
    "key" : "key2",
    "values" : [ "value1", "value2" ]
  } ],
  "tags_any" : [ {
    "key" : "key1",
    "values" : [ "value1", "value2" ]
  } ],
  "not_tags_any" : [ {
    "key" : "key1",
    "values" : [ "value1", "value2" ]
  } ],
  "sys_tags" : [ {
    "key" : "_sys_enterprise_project_id",
    "values" : [ "5aa119a8-d25b-45a7-8d1b-88e127885635" ]
  } ],
  "matches" : [ {
    "key" : "resource_name",
    "value" : "resource1"
  } ]
}

Example Responses

Status code: 200

OK

{
  "total_count" : 1000
}

Status Codes

Status Code

Description

200

OK

400

Invalid parameter.

401

Authentication failed.

403

Insufficient permissions.

404

No resources found.

500

System error.

Error Codes

See Error Codes.