Help Center/ Cloud Bastion Host/ API Reference/ API Description/ Label Management/ Counting the Number of Instances with a Specified Tag
Updated on 2025-12-01 GMT+08:00

Counting the Number of Instances with a Specified Tag

Function

This API is used to count the number of instances with a specified tag.

Calling Method

For details, see Calling APIs.

URI

POST /v2/{project_id}/cbs/instance/count

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID.

To obtain the value, see Obtaining a Project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

You can obtain it by calling the IAM API for obtaining a user token. The token is the value of X-Subject-Token in the response header.

For details, see Obtaining a User Token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

without_any_tag

No

Boolean

Specifies any tag that is not contained. 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.

tags

No

Array of Tags 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 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 tag key and each value of the same tag key must be unique.

  • Resources containing all the specified tags are returned. Keys are in the AND relationship and values in each key-value structure are in the OR relationship.

  • If no tag is specified, all resources are returned.

tags_any

No

Array of Tags objects

  • The instances to be queried contain any tag listed in this field. Each instance to be queried contains a maximum of 50 keys. Each tag key has a maximum of 10 tag values.

  • Each tag value 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.

  • Resources with any tag listed in this field will be returned. 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

No

Array of Tags objects

  • The instances to be queried do not contain any tag listed in this field. Each instance to be queried contains a maximum of 50 keys. Each tag key has a maximum of 10 tag values.

  • Each tag value 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.

  • Resources without the tags listed in this field will be returned. Keys are in the AND relationship and values in each key-value structure are in the OR relationship.

  • If no filtering condition is specified, full data is returned.

not_tags_any

No

Array of Tags objects

  • The resources to be queried do not contain any tag listed in this field. Each resource to be queried contains a maximum of 50 keys. Each tag key can have a maximum of 10 tag values.

  • Each tag value 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.

  • Resources without any tag listed in this field will be returned. Keys 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.

sys_tags

No

Array of Tags 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, each key can contain only one value for calling by TMS. 0 indicates the default enterprise project.

  • sys_tags and tenant tag filtering conditions (without_any_tag, tags, tags_any, not_tags, and not_tags_any) cannot be used at the same time.

  • If sys_tags is not used, resources are filtered by tag. If no tag filtering condition is specified, all data will be returned.

matches

No

Array of Match objects

  • Search field. key indicates the field to be matched, for example, resource_name.

  • 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.

  • resource_id: exact match is used. Only resource_name is supported currently. More fields will be supported later.

Table 4 Tags

Parameter

Mandatory

Type

Description

key

Yes

String

The tag key.

  • A key can contain 1 to 128 characters. It cannot be left blank. UTF-8 letters, digits, spaces, and the following characters are allowed: _ . :=+ - @. sys is reserved as the prefix of system tags and cannot be used by users. Recommended regular expression: ^((?!sys)[\p{L}\p{Z}\p{N}_.:=+\-@]*)$.c

values

Yes

Array of strings

The tag value list.

  • Length: 0 to 255 characters

  • UTF-8 letters, digits, spaces, and the following characters are allowed: _ . :/=+-@. Recommended regular expression: ^([\p{L}\p{Z}\p{N}_.:/=+-@]*)$. The tag value can be empty or null. The predefined tag value cannot be empty.

Table 5 Match

Parameter

Mandatory

Type

Description

key

Yes

String

The tag key. Only resource_name is supported currently. More options will be available later.

value

Yes

String

The tag value. It can contain a maximum of 255 Unicode characters. The character set range is not verified.

Response Parameters

Status code: 200

Table 6 Response body parameters

Parameter

Type

Description

total_count

Integer

Total records.

Status code: 400

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

Error code

error_description

String

Incorrect request parameters.

Status code: 401

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

Error code

error_description

String

Failed to verify the token.

Status code: 403

Table 9 Response body parameters

Parameter

Type

Description

error_code

String

Error code

error_description

String

Permissions required.

Status code: 404

Table 10 Response body parameters

Parameter

Type

Description

error_code

String

Error code

error_description

String

Not CBH instances found.

Example Requests

{
  "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" ]
  } ],
  "sys_tags" : [ {
    "key" : "_sys_enterprise_project_id",
    "values" : [ "5aa119a8-d25b-45a7-8d1b-88e127885635" ]
  } ]
}

Example Responses

Status code: 200

Show Project Tags Success

{
  "total_count" : 1000
}

Status Codes

Status Code

Description

200

Show Project Tags Success

400

Bad Request

401

Unauthorized

403

Forbidden

404

Not Found

Error Codes

See Error Codes.