Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ VPC Endpoint/ API Reference/ APIs/ Tag Function/ Querying Resources by Tag

Querying Resources by Tag

Updated on 2022-12-06 GMT+08:00

Function

This API is used to query resources under the tenant using tags.

URI

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

Table 1 describes the required parameters.
Table 1 Parameter description

Parameter

Mandatory

Type

Description

project_id

Yes

String

Specifies the project ID.

resource_type

Yes

String

Specifies the resource type. The type is endpoint_service or endpoint.

Request

  • Parameter description
    Table 2 Request parameters

    Parameter

    Mandatory

    Type

    Description

    tags

    No

    List<tag>

    Lists tags that are included. Each resource to be queried contains a maximum of 10 keys. Each tag key can have a maximum of 10 tag values. The tag value corresponding to each tag key can be an empty array but the structure cannot be missing. Each tag key and each value of the same tag key must be unique. The response returns resources containing all tags in this list. Keys in this list are in an AND relationship while values in each key-value structure are in an OR relationship. If no tag filtering condition is specified, full data is returned.

    tags_any

    No

    List<tag>

    Lists any tags that are included. Each resource to be queried contains a maximum of 10 keys. Each tag key can have a maximum of 10 tag values. The tag value corresponding to each tag key can be an empty array but the structure cannot be missing. Each tag key and each value of the same tag key must be unique. The response returns resources containing the tags in this list. Keys in this list are in an OR relationship and values in each key-value structure are also in an OR relationship. If no tag filtering condition is specified, full data is returned.

    not_tags

    No

    List<tag>

    Lists tags that are not included. Each resource to be queried contains a maximum of 10 keys. Each tag key can have a maximum of 10 tag values. The tag value corresponding to each tag key can be an empty array but the structure cannot be missing. Each tag key and each value of the same tag key must be unique. The response returns resources containing no tags in this list. Keys in this list are in an AND relationship while values in each key-value structure are in an OR relationship. If no tag filtering condition is specified, full data is returned.

    not_tags_any

    No

    List<tag>

    Lists any tags that are not included. Each resource to be queried contains a maximum of 10 keys. Each tag key has a maximum of 10 tag values. The tag value corresponding to each tag key can be an empty array but the structure cannot be missing. Each tag key and each value of the same tag key must be unique. The response returns resources containing no tags in this list. Keys in this list are in an AND relationship while values in each key-value structure are in an OR relationship. If no tag filtering condition is specified, full data is returned.

    limit

    No

    String

    Sets the page size. This parameter is unavailable when action is set to count. The default size is 1000 when action is set to filter. The maximum value is 1000, and the minimum size is 1. The size cannot be a negative number.

    offset

    No

    String

    Specifies the index position. This parameter is unavailable when action is set to count. If offset is set to N, the resource query starts from the N+1 piece of data. If action is set to filter, offset is 0 by default, indicating that the query starts from the first piece of data. offset must be a positive number.

    action

    Yes

    String

    Specifies the operation to perform. The operation can only be filter (filtering) or count (querying the total number).

    If action is set to filter, the query is performed based on the filter conditions. If action is set to count, only the total number of records is returned.

    matches

    No

    List<match>

    Specifies the search field. The tag key is the field to be matched, for example, resource_name. value indicates the matched value. The key is a fixed dictionary value and cannot contain duplicate keys or unsupported keys.

    Check whether fuzzy match is required based on the key value. For example, if key is set to resource_name, fuzzy search (case-insensitive) is performed by default. If value is empty, exact match is performed. Most services do not have resources without names. In this case, an empty list is returned. If key is resource_id, exact match is used. Only resource_name for key is supported. Other key values will be available later.

    Table 3 Description of field tag

    Parameter

    Mandatory

    Type

    Description

    key

    Yes

    String

    Specifies the tag key. Each tag key contains a maximum of 127 unicode characters but cannot be left blank. The system does not verify the character set of key when searching for resources. key cannot be empty, an empty string, or spaces. Before using key, delete single-byte character (SBC) spaces before and after the value.

    values

    Yes

    List<String>

    Lists tag values. Each value contains a maximum of 255 Unicode characters. Before using values, delete SBC spaces before and after the value.

    The value can be an empty array but cannot be left blank.

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

    The system does not verify the character set of values when searching for resources, but only verifies the length.

    Table 4 Description of field match

    Parameter

    Mandatory

    Type

    Description

    key

    Yes

    String

    Specifies the tag key. Only resource_name for key is supported. Other key values will be available later.

    value

    Yes

    String

    Specifies the tag value. Each value contains a maximum of 255 Unicode characters. The character set of value is not verified.

  • Example request

    POST https://{endpoint}/v1/{project_id}/endpoint_service/resource_instances/action

    or POST https://{endpoint}/v1/{project_id}/endpoint/resource_instances/action

    or POST https://{endpoint}/v1/{project_id}/{resource_type}/resource_instances/action

    • Request body 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"
                  ]
              }
          ]
      }
    • Request body 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 Parameter description

    Parameter

    Type

    Description

    resources

    List<resource>

    N/A

    total_count

    Integer

    Specifies the total number of records.

    Table 6 Data structure of field resource

    Parameter

    Type

    Description

    resource_id

    String

    Specifies the resource ID, which can be Endpoint Service ID or Endpoint ID.

    tags

    List<resource_tag>

    Lists the tags. If no tag is matched, an empty array is returned.

    resource_name

    String

    Specifies the resource name. If the resource does not have a name, the ID is returned.

    Table 7 Data structure of field resource_tag

    Parameter

    Type

    Description

    key

    String

    Specifies the tag key.

    value

    String

    Specifies the tag value.

  • Example response
    • Response body when action is set to filter
      {
          "resources": [
              {
                  "resource_detail": null,
                  "resource_id": "cdfs_cefs_wesas_12_dsad",
                  "resource_name": "resource1",
                  "tags": [
                      {
                          "key": "key1","value": "value1"
                      },
                      {
                          "key": "key2","value": "value1"
                      }
                  ]
              }
          ],
          "total_count": 1000
      }
    • Response body when action is set to count
      {
          "total_count": 1000
      }

Status Code

For details about status codes, see Status Code.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback