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

Querying Security Groups by Tag

Function

This API is used to query security group by tag.

Debugging

You can debug this API through automatic authentication in API Explorer.

URI

POST /v2.0/{project_id}/security-groups/resource_instances/action

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

action

Yes

String

Operation

The value can be filter or count.

limit

No

Integer

Number of records to be queried.

Value range: 1 to 1000

This parameter is not available when action is set to count. The default value is 1000 when action is set to filter.

offset

No

Integer

Index position. The query starts from the next data record indexed by this parameter. You do not need to specify this parameter when you query resources on the first page. When you query resources on subsequent pages, set this parameter to the location returned in the response body for the previous query.

This parameter is not available when action is set to count. If action is set to filter, the value must be a number, and the default value is 0. The value cannot be a negative number.

matches

No

Array of Match objects

Search criteria. The tag key is the field to match, and the tag value indicates the matched value.

Currently, only resource_name is supported.

tags

No

Array of ListTag objects

Included tags. Each tag contains a maximum of 10 keys, and each key contains a maximum of 10 values. The structure body cannot be missing, and the key cannot be left blank or set to an empty string. Each tag key must be unique, and each tag value in a tag must be unique.

Table 3 Match

Parameter

Mandatory

Type

Description

key

Yes

String

Key. The tag key can only be the resource name.

value

Yes

String

Value. Each value can contain a maximum of 255 Unicode characters and cannot contain special characters, such as dollar signs ($), hyphens (-), periods (.), or slashes (/).

Maximum: 255

Table 4 ListTag

Parameter

Mandatory

Type

Description

key

Yes

String

Tag key.

The key cannot be left blank.

Minimum: 1

Maximum: 127

values

Yes

Array of strings

Tag values.

If values are null, it indicates any_value. All values of a tag key are in the OR relationship.

Response Parameters

Status code: 200

Table 5 Response body parameters

Parameter

Type

Description

resources

Array of ListResourceResp objects

Resources

total_count

Integer

Number of resources.

Table 6 ListResourceResp

Parameter

Type

Description

resource_detail

Object

Resource details used for extension, which is left blank by default.

resource_id

String

Resource ID

resource_name

String

Resource name. If there is no resource name, this parameter is an empty string by default.

tags

Array of ResourceTag objects

A list of tags. This parameter is an empty array by default if there is no tag.

Table 7 ResourceTag

Parameter

Type

Description

key

String

  • Definition: Tag key.

  • Constraints:

    • Cannot be left blank.

    • Can contain a maximum of 128 characters.

    • Must be unique for each resource.

    • Can contain letters, digits, underscores (_), and hyphens (-).

value

String

  • Definition: Tag value.

  • Constraints:

    • Can contain a maximum of 255 characters.

    • Can contain letters, digits, underscores (_), periods (.), and hyphens (-).

Example Requests

  • example-1: Request body when action is set to filter

    POST https://{Endpoint}/v2.0/{project_id}/security-groups/resource_instances/action
    
    {
      "offset" : "0",
      "limit" : "100",
      "action" : "filter",
      "matches" : [ {
        "key" : "resource_name",
        "value" : "resource1"
      } ],
      "tags" : [ {
        "key" : "key1",
        "values" : [ "*value1", "value2" ]
      } ]
    }
  • example-2: Request body when action is set to count

    POST https://{Endpoint}/v2.0/{project_id}/security-groups/resource_instances/action
    
    {
      "action" : "count",
      "tags" : [ {
        "key" : "key1",
        "values" : [ "value1", "value2" ]
      }, {
        "key" : "key2",
        "values" : [ "value1", "value2" ]
      } ],
      "matches" : [ {
        "key" : "resource_name",
        "value" : "resource1"
      } ]
    }

Example Responses

Status code: 200

The response to the request is normal. If action in the request body is set to filter, the resource tag list is returned. If action in the request body is set to count, the total number of tags is returned. For more status codes, see Status Codes.

{
  "resources" : [ {
    "resource_id" : "cdfs_cefs_wesas_12_dsad",
    "resource_name" : "resouece1",
    "tags" : [ {
      "key" : "key1",
      "value" : "value1"
    }, {
      "key" : "key2",
      "value" : "value1"
    } ]
  } ],
  "total_count" : 1000
}

Status Codes

Status Code

Description

200

The response to the request is normal. If action in the request body is set to filter, the resource tag list is returned. If action in the request body is set to count, the total number of tags is returned. For more status codes, see Status Codes.

Error Codes

See Error Codes.