Updated on 2023-11-24 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

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

project_id

string

path

Yes

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

Requests

  • Parameter description
    Table 2 Parameter description

    Name

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

    tags

    Array of objects

    No

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

    Table 3 tags field data structure description

    Name

    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 4 matches field description

    Name

    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.

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"
        }
      ]
    }

Responses

  • Parameter description
    Table 5 Parameter description

    Name

    Type

    Description

    instances

    Array of objects

    The instance list. For details, see Table 6.

    total_count

    Integer

    The total number of queried records.

    Table 6 instance field data structure description

    Name

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

    Table 7 tags field data structure description

    Name

    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 (including Chinese characters), 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 "-".

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