Updated on 2025-06-30 GMT+08:00

Querying Resources by Tag

Function

This API is used to query resources by tag.

API Calling

For details, see Calling APIs.

URI

POST /v3/{project_id}/{resource_type}/resource-instances/filter

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID.

resource_type

Yes

String

Resource type. The value is fixed to cts-tracker for CTS.

Table 2 Query parameters

Parameter

Mandatory

Type

Description

limit

No

Integer

Number of records to be queried, which ranges from 1 to 1,000. If this parameter is not passed, the default value is 1000.

offset

No

String

Index position. The query starts from the next data specified by offset. The value must be a number and cannot be negative. The default value is 0.

Request Parameters

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

without_any_tag

No

Boolean

Whether to query only untagged resources. If this parameter is set to true, all resources without tags are queried. In this case, the tags field is ignored. If this parameter is set to false or not specified, it does not take effect, meaning that all resources are returned or resources are filtered by tags or matches.

tags

No

Array of TmsTags objects

Tag list. A maximum of 20 keys can be included. Each key has a maximum of 20 values.

matches

No

Array of Match objects

Field to be matched. This parameter specifies the key-value pair to be matched in the query. If value is left blank, exact matching will work. Otherwise, fuzzy matching will work.

Table 4 TmsTags

Parameter

Mandatory

Type

Description

key

No

String

Tag key, which can contain a maximum of 128 Unicode characters. A tag key can contain letters, digits, spaces, and special characters (_.:=+-@) but cannot start or end with a space.

values

No

Array of strings

Value list.

Table 5 Match

Parameter

Mandatory

Type

Description

key

No

String

Key to be matched. It can only be resource_name.

value

No

String

Value to be matched. Each value can contain up to 255 Unicode characters. It cannot contain underscores (_) or percent signs (%).

Response Parameters

Status code: 200

Table 6 Response body parameters

Parameter

Type

Description

resources

Array of Resource objects

Resource tag details.

total_count

Integer

Total number of records in the list, which is irrelevant to pagination.

Table 7 Resource

Parameter

Type

Description

resource_id

String

Resource ID.

resource_detail

String

Resource details. The value is a resource object, used for extension. This parameter is left blank by default.

tags

Map<String,ResourceTag>

Tag list. If there is no tag in the list, an empty array is returned.

resource_name

String

Resource name.

Table 8 ResourceTag

Parameter

Type

Description

key

String

Tag key, which can contain a maximum of 128 Unicode characters. A tag value can contain letters, digits, spaces, and special characters (_.:/=+-@). It cannot start or end with a space, or start with _sys_.

value

String

Tag value, which can contain a maximum of 255 Unicode characters. If value is specified, tags are deleted by key and value. If value is not specified, tags are deleted by key. A tag value can contain letters, digits, spaces, and special characters (_.:/=+-@) but cannot start or end with a space.

Example Request

Querying resources by tag

https://{endpoint}/v3/{project_id}/{resource_type}/resource-instances/filter

{
  "offset" : "100",
  "limit" : "100",
  "action" : "filter",
  "without_any_tag" : true,
  "tags" : [ {
    "key" : "key1",
    "values" : [ "*value1", "value2" ]
  } ],
  "tags_any" : [ {
    "key" : "key1",
    "values" : [ "*value1", "value2" ]
  } ],
  "not_tags" : [ {
    "key" : "key1",
    "values" : [ "*value1", "value2" ]
  } ],
  "not_tags_any" : [ {
    "key" : "key1",
    "values" : [ "*value1", "value2" ]
  } ],
  "sys_tags" : [ {
    "key" : "key1",
    "values" : [ "*value1", "value2" ]
  } ],
  "matches" : [ {
    "key" : "resource_name",
    "value" : "resource1"
  } ]
}

Example Response

Status code: 200

The request is successful.

{
  "total_count" : 1000,
  "resources" : [ {
    "resource_detail" : "",
    "resource_id" : "xxx",
    "resource_name" : "system",
    "tags" : [ {
      "key" : "_sys_enterprise_project_id",
      "value" : "0"
    }, {
      "key" : "key1",
      "value" : "value1"
    } ]
  } ]
}

Status Codes

Status Code

Description

200

The request is successful.

Error Codes

For details, see Error Codes.