• Domain Name Service

dns
  1. Help Center
  2. Domain Name Service
  3. API Reference
  4. API Description
  5. Tag Management
  6. Querying Resources by Tag

Querying Resources by Tag

Function

Query DNS resources by tag.

TMS uses this API to filter and list service resources.

Resources are sorted by creation time in descending order.

URI

POST /v2/{project_id}/{resource_type}/resource_instances/action

For details, see Table 1.
Table 1 Parameters in the URI

Parameter

Mandatory

Type

Description

project_id

Yes

string

Project ID of the tenant

resource_type

Yes

string

Resource type, which can be DNS-public_zone, DNS-private_zone, DNS-public_recordset, DNS-private_recordset, or DNS-ptr_record

Request

  • Parameter description
    Table 2 Parameters in the request

    Parameter

    Mandatory

    Type

    Description

    tags

    No

    List<tag>

    Includes specified tags.

    The structure body is mandatory. A maximum of 10 tag keys are allowed in each query operation. The tag key cannot be left blank or set to the empty string. One tag key can have up to 10 tag values. Each tag key must be unique, and the tag values of one key must also be unique.

    tags_any

    No

    List<tag>

    Includes any of the specified tags.

    The structure body is mandatory. A maximum of 10 tag keys are allowed in each query operation. The tag key cannot be left blank or set to the empty string. One tag key can have up to 10 tag values. Each tag key must be unique, and the tag values of one key must also be unique.

    not_tags

    No

    List<tag>

    Excludes specified tags.

    The structure body is mandatory. A maximum of 10 tag keys are allowed in each query operation. The tag key cannot be left blank or set to the empty string. One tag key can have up to 10 tag values. Each tag key must be unique, and the tag values of one key must also be unique.

    not_tags_any

    No

    List<tag>

    Excludes any of the specified tags.

    The structure body is mandatory. A maximum of 10 tag keys are allowed in each query operation. The tag key cannot be left blank or set to the empty string. One tag key can have up to 10 tag values. Each tag key must be unique, and the tag values of one key must also be unique.

    limit

    No

    string

    Maximum number of resources to be queried

    If the value of action is set to filter, this parameter takes effect. Its value ranges from 1 to 1000 (default).

    If action is set to count, this parameter does not take effect.

    offset

    No

    string

    Start location of pagination query

    The value ranges from 0 to 2,147,483,647.

    The query starts from the next resource of the specified location.

    You do not need to specify this parameter when querying resources on the first page.

    When you query resources on subsequent pages, set the value of offset to the location returned in the response body for the previous query.

    If action is set to filter, this parameter takes effect. Its value can be 0 (default) or a positive integer.

    If action is set to count, this parameter does not take effect.

    action

    Yes

    string

    Operation to be performed

    The value can be filter or count (case-sensitive).

    filter: queries resources in pages by filter condition.

    count: queries the total number of resources.

    matches

    No

    List<match>

    Field to be matched

    This parameter specifies the key-value pair to be matched in the query.

    If value is left blank, an exact match is performed. Otherwise, a fuzzy match is performed.

    Table 3 Parameters in the tag list

    Parameter

    Mandatory

    Type

    Description

    key

    Yes

    string

    Tag key. A key contains 127 Unicode characters and cannot be blank. (This parameter is not verified in the search process.)

    values

    Yes

    List<String>

    Values of the tag.

    A value contains a maximum of 255 Unicode characters.

    The asterisk (*) is a reserved character.

    If the value starts with an asterisk, the string following the asterisk is fuzzy matched.

    If this parameter is not specified, any value is matched. The values are in OR relationship.

    Table 4 Parameters in the matches field

    Parameter

    Mandatory

    Type

    Description

    key

    Yes

    string

    Key to be matched. Currently, it can only be resource_name.

    value

    Yes

    string

    Value to be matched. It contains a maximum of 255 Unicode characters and cannot contain underscores (_) and percent sign (%).

  • Example request
    The following is a request example when action is set to filter:
    {
        "offset": "100", 
        "limit": "100", 
        "action": "filter", 
        "matches": [
            {
                "key": "resource_name", 
                "value": "resource1"
            }
        ], 
        "not_tags": [
            {
                "key": "key1", 
                "values": [
                    "*value1", 
                    "value2"
                ]
            }
        ], 
        "tags": [
            {
                "key": "key1", 
                "values": [
                    "*value1", 
                    "value2"
                ]
            }
        ], 
        "tags_any": [
            {
                "key": "key1", 
                "values": [
                    "value1", 
                    "value2"
                ]
            }
        ], 
        "not_tags_any": [
            {
                "key": "key1", 
                "values": [
                    "value1", 
                    "value2"
                ]
            }
        ]
    }
    The following is a request example when action is set to count:
    {
        "action": "count", 
        "not_tags": [
            {
                "key": "key1", 
                "values": [
                    "value1", 
                    "*value2"
                ]
            }
        ], 
        "tags": [
            {
                "key": "key1", 
                "values": [
                    "value1", 
                    "value2"
                ]
            }, 
            {
                "key": "key2", 
                "values": [
                    "value1", 
                    "value2"
                ]
            }
        ], 
        "tags_any": [
            {
                "key": "key1", 
                "values": [
                    "value1", 
                    "value2"
                ]
            }
        ], 
        "not_tags_any": [
            {
                "key": "key1", 
                "values": [
                    "value1", 
                    "value2"
                ]
            }
        ], 
        "matches": [
            {
                "key": "resource_name", 
                "value": "resource1"
            }
        ]
    }

Response

  • Parameter description
    Table 5 Parameters in the response

    Parameter

    Type

    Description

    resources

    List<resource>

    Resource list

    total_count

    int

    Total number of resources

    Table 6 Parameters in the resources field

    Parameter

    Type

    Description

    resource_id

    String

    Resource ID

    resource_detail

    Object

    Resource details. This field is reserved for subsequent extension, and its value defaults to an empty string.

    tags

    List<tag>

    List of queried tags. If no tag is matched, an empty array is returned.

    resource_name

    String

    Resource name. If no resource name is matched, the value is left blank.

    Table 7 Parameters in the tag list

    Parameter

    Mandatory

    Type

    Description

    key

    Yes

    string

    Tag key, which contains 36 Unicode characters at most and cannot be blank. It can contain only digits, letters, hyphens (-), and underscores (_).

    value

    Yes

    string

    Tag value, which contains 43 Unicode characters at most and can be an empty string. It can contain only digits, letters, hyphens (-), and underscores (_).

  • Example response
    The following is a request example when action is set to filter:
    {
        "resources": [
            {
                "resource_detail": null, 
                "resource_id": "cdfs_cefs_wesas_12_dsad", 
                "resource_name": "resouece1", 
                "tags": [
                    {
                        "key": "key1", 
                        "value": "value1"
                    }, 
                    {
                        "key": "key2", 
                        "value": "value1"
                    }
                ]
            }
        ], 
        "total_count": 1000
    }
    The following is a request example when action is set to count:
    {
        "total_count": 1000
    }

Returned Value

  • Normal
    Table 8 Return code for successful requests

    Returned Value

    Description

    204

    No content.

  • Abnormal
    Table 9 Return code for failed requests

    Returned Value

    Description

    400

    Invalid tag.

    401

    Authentication failed.

    403

    Insufficient permission.

    404

    The requested resource was not found.

    500

    An exception occurs in the system.