Querying Resources by Tag

Function

This API is used to query resources in a project by tag.

By default, resources and resource tags are in descending order of their creation time.

URI

POST /autoscaling-api/v1/{project_id}/{resource_type}/resource_instances/action

Table 1 Parameter description

Parameter

Mandatory

Type

Description

project_id

Yes

String

Specifies the project ID.

resource_type

Yes

String

Specifies the resource type. An example value is scaling_group_tag.

Request

Table 2 Request parameters

Parameter

Mandatory

Type

Description

tags

No

Array of Tag objects

Specifies filter criteria with tags included. A maximum of 10 keys can be contained. The structure body must be complete. For details, see Table 3.

tags_any

No

Array of Tag objects

Specifies filter criteria with any tag included. A maximum of 10 keys can be contained. For details, see Table 3.

not_tags

No

Array of Tag objects

Specifies filter criteria without tags included. A maximum of 10 keys can be contained. For details, see Table 3.

not_tags_any

No

Array of Tag objects

Specifies filter criteria without any tag included. A maximum of 10 keys can be contained. For details, see Table 3.

limit

No

String

Specifies the maximum number of query records. The maximum value is 1,000, and the minimum value is 1.

  • If action is set to count, this parameter is invalid.
  • If action is set to filter, the default value is 1000.

marker

No

String

Marks the paging location (index position). You are advised to use the offset parameter to set the index position.

Marks the paging location (resource ID or index location).

action

Yes

String

Specifies the operation, which can be filter or count.

  • filter: indicates that resources are filtered by tag and the resources meeting the search criteria are returned on pages.
  • count: indicates that resources are searched by tag and the number of resources meeting the search criteria is returned.

offset

No

String

Specifies the index position. The query starts from the next image indexed by this parameter. The value must be a non-negative number.

You do not need to specify this parameter when querying resources on the first page. When you query resources on subsequent pages, set offset to the location returned in the response body for the previous query.

  • If the action value is count, this parameter is invalid.
  • If the action value is filter, the default value is 0.

matches

No

Array of match objects

Specifies fuzzy search. For details, see Table 4.

without_any_tag

Yes

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.

Table 3 Tag field description

Parameter

Mandatory

Type

Description

key

Yes

String

Specifies the tag key. It contains a maximum of 36 Unicode characters. It cannot be left blank (This parameter is not verified in the search process.) A maximum of 10 keys are allowed and the key cannot be left blank or an empty string. Each key must be unique.

values

Yes

Array of strings

Specifies tag values. A value contains a maximum of 43 Unicode characters. A key contains a maximum of 10 values. Each value of the same key must be unique.

  • The asterisk (*) is reserved for the system. If the value starts with *, it indicates that fuzzy match is performed for the digits following *. The value cannot contain only asterisks (*).
  • If the values are null (not default), it indicates any_value (querying any value). The resources contain one or multiple values listed in values will be found and displayed.
Table 4 match field description

Parameter

Mandatory

Type

Description

key

Yes

String

Specifies the key based on which to query resources.

The parameter value can only be resource_name.

value

Yes

String

Specifies the value. The value is a fixed dictionary value. A value contains a maximum of 255 Unicode characters. If the value is an empty string or resource_id, exact match is used.

Example Request

Response

Table 5 Response parameters

Parameter

Type

Description

resources

Array of Resource objects

Specifies tag resources. For details, see Table 6.

total_count

Integer

Specifies the total number of records. When action is set to count, only this parameter is returned. The values of resources and marker are not returned.

marker

String

Specifies the paging location identifier.

Table 6 Resource field description

Parameter

Type

Description

resource_id

String

Specifies the resource ID.

resource_detail

String

Specifies the resource details.

tags

Array of ResourceTag objects

Specifies tags. If there is no tag, the field tags is taken as an empty array by default. For details, see Table 7.

resource_name

String

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

Table 7 ResourceTag field description

Parameter

Type

Description

key

String

Specifies the tag key. It contains a maximum of 36 Unicode characters.

value

String

Specifies the tag value. It contains a maximum of 43 Unicode characters.

Example Response

Returned Values

Error Codes

See Error Codes.