Updated on 2024-12-03 GMT+08:00

Querying the Resource Instance List

Function

This API is used to query resource instances based on tags.

Calling Method

For details, see Calling APIs.

URI

POST /v5/{project_id}/{resource_type}/resource-instances/filter

Table 1 Parameter description

Parameter

Type

Mandatory

Description

project_id

String

Yes

Specifies a project ID. You can obtain the project ID by referring to Obtaining the Project ID.

resource_type

String

Yes

  • Specifies the resource type.
  • The value can be one of the following: vpn-gateway, customer-gateway, vpn-connection, p2c-vpn-gateways.
Table 2 Parameter in a query request

Parameter

Type

Mandatory

Description

limit

Integer

No

  • Specifies the number of records to be queried.
  • The value ranges from 1 to 1000.
  • The default value is 1000.

offset

Integer

No

  • Specifies the index position. The query starts from the (offset value + 1)th data record.
  • The minimum value is 0.
  • The default value is 0.

Request

  • Request parameters
    Table 3 Request parameters

    Parameter

    Type

    Mandatory

    Description

    without_any_tag

    Boolean

    No

    • When this parameter is set to true, all resources without tags are queried. In this case, the tags field is ignored. If this parameter is set to false or is not specified, all resources are queried or resources are filtered by "tags" or "matches".

    tags

    Array of Tag objects

    No

    • Specifies a tag list.
    • A maximum of 20 tags can be specified.

    matches

    Array of Match objects

    No

    • Specifies a search field, including a key and a value. The match key is the field to be matched, for example, resource_name. The match value is the value to be matched. The key is a fixed dictionary value.
    Table 4 Tag

    Parameter

    Type

    Mandatory

    Description

    key

    String

    Yes

    • Specifies a tag key.
    • The value is a string of 1 to 128 characters.

    values

    Array of String

    Yes

    • Specifies the value list of a tag. If values is an empty list, it indicates any_value. The relationship between values is OR.
    • The value is a sting of 0 to 255 characters.
    • A maximum of 20 values can be specified.
    Table 5 Match

    Parameter

    Type

    Mandatory

    Description

    key

    String

    Yes

    • Specifies a match key.
    • The value is resource_name.

    value

    String

    Yes

    • Specifies a match value.
    • The value is a sting of 0 to 255 characters.
  • Example request
    POST https://{Endpoint}/v5/{project_id}/{resource_type}/resource-instances/filter
    {
        "tags": [{
                "key": "key1",
                "values": [
                    "value1",
                    "value2"
                ]
            },
            {
                "key": "key2",
                "values": [
                    "value1",
                    "value2"
                ]
            }
        ],
        "matches": [{
            "key": "resource_name",
            "value": "resource1"
        }],
        "without_any_tag": "false"
    }

Response

  • Response parameters

    Returned status code 200: successful query

    Table 6 Parameters in the response body

    Parameter

    Type

    Description

    resources

    Array of Resource objects

    Indicates the resource object list.

    total_count

    Integer

    Indicates the total number of records.

    Table 7 Resource

    Parameter

    Type

    Description

    resource_id

    String

    Indicates a resource ID.

    resource_detail

    object

    Specifies resource details. This parameter is reserved for extension and is left empty by default.

    tags

    Array of ResourceTag objects

    Specifies a tag list.

    resource_name

    String

    Indicates a resource name.

    Table 8 ResourceTag

    Parameter

    Type

    Description

    key

    String

    Indicates a tag key.

    value

    String

    Indicates a tag value.

  • Example response
    {
        "resources": [{
            "resource_id": "134f9fb1-demo-a8df-va86-2040a5c13325",
            "resource_name": "resouece1",
            "tags": [{
                "key": "key1",
                "value": "value1"
            }]
        }],
        "total_count": 1000
    }

Status Codes

For details, see Status Codes.