Updated on 2026-01-08 GMT+08:00

Querying Resources by Tag

Description

This API is used to query the specified DB instances by tag.

Restrictions

A maximum of 10 tags can be added to a DB instance. The tag key must be unique.

URI

  • URI format

    POST https://{Endpoint}/v3/{project_id}/instances/action

Table 1 Path parameters

Name

Type

IN

Mandatory

Description

project_id

string

path

Yes

Project ID of a tenant in a region. To obtain the project ID, see Obtaining a Project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Type

IN

Mandatory

Description

X-Auth-Token

string

header

Yes

User token

Table 3 Parameter description

Parameter

Type

Mandatory

Description

offset

String

No

The index position. The query starts from the next piece of data indexed by this parameter.

  • If action is set to count, this parameter is not transferred.
  • If action is set to filter, this parameter must be a positive integer. The default value is 0, indicating that the query starts from the first piece of data.

limit

String

No

The number of resources to be queried.

  • If action is set to count, this parameter is not transferred.
  • If action is set to filter, the value range is from 1 to 100. If this parameter is not transferred, the first 100 DB instances are queried by default.

action

String

Yes

The operation identifier.

  • If action is set to filter, instances are queried by tag filtering criteria.
  • If action is set to count, only the total number of records is returned.

matches

Array of objects

No

The search field.

  • If the value is left blank, the query is not based on the instance name or instance ID.
  • If the value is not empty, see Table 5.

tags

Array of objects

No

The included tags. Each tag contains a maximum of 10 keys. For more information, see Table 4.

Table 4 tags field data structure description

Parameter

Type

Mandatory

Description

key

String

Yes

The tag key.

  • The key cannot be empty and contains 1 to 128 single-byte characters.
  • The key can contain UTF-8 letters (including Chinese characters), digits, spaces, and the following characters: _.:/=+-@
  • Do not enter labels starting with _sys_, which are system labels.
NOTE:

The character set of this parameter is not verified in the search process.

values

Array of strings

Yes

Lists the tag values.

  • The value can contain UTF-8 letters (including Chinese characters), digits, spaces, and the following characters: _.:/=+-@
  • The value can be empty or null and contains 0 to 255 single-byte characters.

If the values are null, it indicates querying any value. The values are in OR relationship.

Table 5 matches field description

Parameter

Type

Mandatory

Description

key

String

Yes

The query criteria. The value can be instance_name or instance_id, indicating that the query is based on the instance name or instance ID.

value

String

Yes

The name or ID of the DB instance to be matched. You can call the API for querying DB instances to obtain the DB instance name or ID. If you do not have an instance, you can call the API used for creating an instance.

  • Request example

    Query specified DB instances by tag.

    {
      "offset": "100",
      "limit": "100",
      "action": "filter",
      "matches": [
        {
          "key": "instance_name",
          "value": "test-single"
        }
      ],
      "tags": [
        {
          "key": "key1",
          "values": [
            "value1",
            "value2"
          ]
        }
      ]
    }
    Query the total number of resources.
    {
      "action": "count",
      "tags": [
        {
          "key": "key1",
          "values": [
            "value1",
            "value2"
          ]
        },
        {
          "key": "key2",
          "values": [
            "value1",
            "value2"
          ]
        }
      ],
      "matches": [
        {
          "key": "instance_name",
          "value": "test-single"
        },
         {
          "key": "instance_id",
          "value": "958693039f284d6ebfb177375711072ein02"
        }
      ]
    }

Response Parameters

Table 6 Parameter description

Parameter

Type

Description

instances

Array of objects

The instance list. For details, see Table 7.

total_count

Integer

The total number of queried records.

Table 7 instance field data structure description

Parameter

Type

Description

instance_id

String

The instance ID, which can be obtained by calling the API for querying instances. If you do not have an instance, you can call the API used for creating an instance.

instance_name

String

The DB instance name.

tags

Array of objects

The tag list. If there is no tag in the list, tags is taken as an empty array. For more information, see Table 8.

Table 8 tags field data structure description

Parameter

Type

Description

key

String

The tag key.

  • The key cannot be empty and contains 1 to 128 single-byte characters.
  • The key can contain UTF-8 letters (including Chinese characters), digits, spaces, and the following characters: _.:/=+-@
  • Do not enter labels starting with _sys_, which are system labels.

Character set: 0-9, A-Z, a-z, "_", and "-".

value

String

The tag value.

  • The value can contain UTF-8 letters, digits, spaces, and the following characters: _.:/=+-@
  • The value can be empty or null and contains 0 to 255 single-byte characters.

Character set: 0-9, A-Z, a-z, "_", ".", and "-".

  • Example response

    Return specified DB instances by tag.

    {
      "instances": [
        {
          "instance_id": "2acbf2223caf3bac3c33c6153423c3ccin02",
          "instance_name": "test-single",
          "tags": [
            {
              "key": "key1",
              "value": "value1"
            },
            {
              "key": "key2",
              "value": "value1"
            }
          ]
        }
      ]
    }

    Number of returned records.

    {
      "total_count": 4
    }

Status Code

For details, see Status Code.

Error Code

For details, see Error Code.