Updated on 2025-08-22 GMT+08:00

Querying Resources by Tag

Description

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

Restrictions

A maximum of 20 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

  • URI example

    https://dds.ap-southeast-1.myhuaweicloud.com/v3/0549b4a43100d4f32f51c01c2fe4acdb/instances/action

Table 1 Request parameters

Name

Type

IN

Mandatory

Description

X-Auth-Token

string

header

Yes

Definition

User token obtained from IAM. For details, see Authentication.

Constraints

N/A

Range

N/A

Default Value

N/A

project_id

string

path

Yes

Definition

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

Constraints

N/A

Range

N/A

Default Value

N/A

Request Parameters

  • Parameter description
    Table 2 Parameter description

    Name

    Type

    Mandatory

    Description

    offset

    String

    No

    Definition

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

    Constraints

    • If action is set to count, this parameter is not transferred.
    • If action is set to filter, this parameter must be a positive integer.

    Range

    N/A

    Default Value

    0. The default value is 0, indicating that the query starts from the first piece of data.

    limit

    String

    No

    Definition

    The number of resources to be queried.

    Constraints

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

    Range

    1 to 100

    Default Value

    100. If this parameter is not transferred, the first 100 DB instances are queried by default.

    action

    String

    Yes

    Definition

    The operation identifier.

    Constraints

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

    Range

    • count
    • filter

    Default Value

    N/A

    matches

    Array of objects

    No

    Definition

    The search field.

    Constraints

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

    Range

    N/A

    Default Value

    N/A

    tags

    Array of objects

    No

    Definition

    Tag. For details, see Table 3.

    Constraints

    A maximum of 20 keys are supported.

    Range

    N/A

    Default Value

    N/A

    Table 3 tags field data structure description

    Name

    Type

    Mandatory

    Description

    key

    String

    Yes

    Definition

    The tag key.

    Constraints

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

    Range

    N/A

    Default Value

    N/A

    values

    Array of strings

    Yes

    Definition

    Lists the tag values.

    Constraints

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

    Range

    N/A

    Default Value

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

    Table 4 matches field description

    Name

    Type

    Mandatory

    Description

    key

    String

    Yes

    Definition

    Search field name.

    Constraints

    N/A

    Range

    • instance_name: indicating that the query is based on the instance name.
    • instance_id: indicating that the query is based on the instance ID.

    Default Value

    N/A

    value

    String

    Yes

    Definition

    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 a DB instance.

    Constraints

    N/A

    Range

    N/A

    Default Value

    N/A

Example Request

  • Querying 1 to 100 specified DB instances by tag
    {
      "offset": "100",
      "limit": "100",
      "action": "filter",
      "matches": [
        {
          "key": "instance_name",
          "value": "test-single"
        }
      ],
      "tags": [
        {
          "key": "key1",
          "values": [
            "value1",
            "value2"
          ]
        }
      ]
    }
  • Querying the total number of resources by instance name or ID
    {
      "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

  • Parameter description
    Table 5 Parameter description

    Name

    Type

    Description

    instances

    Array of objects

    Definition

    The instance list. For details, see Table 6.

    Range

    N/A

    total_count

    Integer

    Definition

    The total number of queried records.

    Range

    N/A

    Table 6 instance field data structure description

    Name

    Type

    Description

    instance_id

    String

    Definition

    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 a DB instance.

    Range

    N/A

    instance_name

    String

    Definition

    The DB instance name.

    Range

    N/A

    tags

    Array of objects

    Definition

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

    Range

    N/A

    Table 7 tags field data structure description

    Name

    Type

    Description

    key

    String

    Definition

    The tag key.

    Range

    • 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.
    • It is case-sensitive and can contain digits, letters, underscores (_), and hyphens (-).

    value

    String

    Definition

    The tag value.

    Range

    • 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.
    • It is case-sensitive and can contain digits, letters, underscores (_), periods (.), and hyphens (-).
  • Response example

    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
    }

SDK

Click Document Database Service DDS SDK to download the SDK or view the SDK document. To learn how to install and authenticate an SDK, read the Usage section.

Status Code

For more information, see Status Code.

Error Code

For more information, see Error Code.