# 查询资源实例 - ListResourceInstances
#### 功能介绍
使用标签过滤实例。
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-smn/smn_api_30000.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-smn/smn_api_80000.html)。
- 如果使用身份策略授权，需具备如下身份策略权限。
  
  | 授权项          | 访问级别 | 资源类型（\*为必须） | 条件键                       | 别名 | 依赖的授权项 |
  |:---|:---|:---|:---|:---|:---|
  | smn:tag:list | Read | topic \*    | g:ResourceTag/\<tag-key\> | -  | -      |
     
  
 
#### URI
POST /v2/{project_id}/{resource_type}/resource_instances/action
表1路径参数 
| 参数            | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                       |
|:---|:---|:---|:---|
| project_id    | 是    | String | 项目ID。获取项目ID请参考 [获取项目ID](https://support.huaweicloud.com/api-smn/smn_api_66000.html)。                                                                                                                                                                                     |
| resource_type | 是    | String | 资源类型，目前有: smn_topic，主题 smn_sms，短信 smn_application，移动推送 |
   
#### 请求参数
表2请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                                                                                              |
|:---|:---|:---|:---|
| X-Auth-Token | 是    | String | 用户Token。 通过调用IAM服务获取用户Token接口获取（响应消息头中X-Subject-Token的值）。 |
   
表3请求Body参数 
| 参数              | 是否必选 | 参数类型                                                                                                       | 描述                                                                                                                                                                                                                                                                                                                                                                                |
|:---|:---|:---|:---|
| tags            | 否    | Array of [ResourceTags] objects | 最多包含10个key，每个key最多包含10个value，结构体不能缺失。key不能为空或者空字符串。key不能重复，同一个key中value不能重复，不同key对应的资源之间为与的关系。                                                                                                                                                                                                                                                                                    |
| tags_any        | 否    | Array of [ResourceTags] objects | 最多包含10个key，每个key最多包含10个value，结构体不能缺失。key不能为空或者空字符串。key不能重复，同一个key中value不能重复，不同key对应的资源之间为或的关系。                                                                                                                                                                                                                                                                                    |
| not_tags        | 否    | Array of [ResourceTags] objects | 最多包含10个key，每个key最多包含10个value，结构体不能缺失。key不能为空或者空字符串。key不能重复，同一个key中value不能重复，不同key对应的资源之间为与非的关系。                                                                                                                                                                                                                                                                                   |
| not_tags_any    | 否    | Array of [ResourceTags] objects | 最多包含10个key，每个key最多包含10个value，结构体不能缺失。key不能为空或者空字符串。key不能重复，同一个key中value不能重复，不同key对应的资源之间为或非的关系。                                                                                                                                                                                                                                                                                   |
| offset          | 否    | String                                                                                                     | 索引位置， 从offset指定的下一条数据开始查询。 查询第一页数据时，不需要传入此参数，查询后续页码数据时，将查询前一页数据时响应体中的值带入此参数。action为count时无此参数。action为filter时，默认为0，必须为数字，且不能为负数。 **默认取值：** 0                                                                                           |
| limit           | 否    | String                                                                                                     | 查询记录数。 action为count时无此参数。 action为filter时，默认为1000。limit最多为1000，不能为负数，最小值为1。 **默认取值：** 1000 |
| action          | 是    | String                                                                                                     | 操作标识（仅限于filter，count）：filter（过滤），count(查询总条数)。 为filter时表示分页查询，为count只需按照条件将总条数返回即可。                                                                                                                                                                                                                         |
| matches         | 否    | Array of [TagMatch] objects         | 搜索字段。 key为要匹配的字段，当前只支持resource_name。 value为匹配的值，当前为精确匹配。                                                                                                                                                                              |
| without_any_tag | 否    | Boolean                                                                                                    | 不包含任意一个标签。该字段为true时查询所有不带标签的资源，此时忽略"tags"、"tags_any"、"not_tags"、"not_tags_any"字段。                                                                                                                                                                                                                                                                                                 |
   
 表4ResourceTags 
| 参数     | 是否必选 | 参数类型             | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
|:---|:---|:---|:---|
| key    | 是    | String           | 键。 - 最大长度128个unicode字符。   - key不能为空。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| values | 是    | Array of strings | 值列表。 - 最多10个value。   - value不允许重复。   - 每个值最大长度256个unicode字符。   - 如果values为空则表示any_value。   - value之间为或的关系。    |
   
 表5TagMatch 
| 参数    | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
|:---|:---|:---|:---|
| key   | 是    | String | 键，表示要匹配的字段。 当前key的参数值只能取"resource_name"，此时value的参数值为云服务器名称。 - key不能重复，value为匹配的值。   - 此字段为固定字典值。   - 不允许为空字符串。    |
| value | 是    | String | 值。 当前key的参数值只能取"resource_name"，此时value的参数值为云服务器名称。 - 每个值最大长度255个unicode字符。   - 不可以为空。                                                                                                                                                                                                                                                                                                                                                                    |
   
#### 响应参数
**状态码：200**
表6响应Body参数 
| 参数          | 参数类型                                                                                                      | 描述       |
|:---|:---|:---|
| resources   | Array of [TagResource] objects | 返回的资源列表。 |
| total_count | Integer                                                                                                   | 总记录数。    |
   
 表7TagResource 
| 参数              | 参数类型                                                                                                      | 描述    |
|:---|:---|:---|
| resource_id     | String                                                                                                    | 资源ID。 |
| resource_detail | [ResourceDetail] object     | 资源详情。 |
| tags            | Array of [ResourceTag] objects | 标签列表。 |
| resource_name   | String                                                                                                    | 资源名称。 |
   
 表8ResourceDetail 
| 参数                    | 参数类型   | 描述        |
|:---|:---|:---|
| enterprise_project_id | String | 企业项目ID    |
| detailId              | String | 详情ID      |
| topic_urn             | String | topic唯一标识 |
| display_name          | String | 显示名       |
   
 表9ResourceTag 
| 参数    | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
|:---|:---|:---|
| key   | String | 键。 - 最大长度128个unicode字符。   - key不能为空。    |
| value | String | 值。 - 每个值最大长度256个unicode字符。                                                                                                                                                                                                                                                                                                                                                     |
   
**状态码：400**
表10响应Body参数 
| 参数         | 参数类型   | 描述          |
|:---|:---|:---|
| request_id | String | 请求的唯一标识ID。  |
| code       | String | 服务异常错误信息编码。 |
| message    | String | 服务异常错误信息描述。 |
   
**状态码：403**
表11响应Body参数 
| 参数         | 参数类型   | 描述          |
|:---|:---|:---|
| request_id | String | 请求的唯一标识ID。  |
| code       | String | 服务异常错误信息编码。 |
| message    | String | 服务异常错误信息描述。 |
   
**状态码：404**
表12响应Body参数 
| 参数         | 参数类型   | 描述          |
|:---|:---|:---|
| request_id | String | 请求的唯一标识ID。  |
| code       | String | 服务异常错误信息编码。 |
| message    | String | 服务异常错误信息描述。 |
   
**状态码：500**
表13响应Body参数 
| 参数         | 参数类型   | 描述          |
|:---|:---|:---|
| request_id | String | 请求的唯一标识ID。  |
| code       | String | 服务异常错误信息编码。 |
| message    | String | 服务异常错误信息描述。 |
   
#### 请求示例
- 使用标签过滤资源实例
  ```
  POST https://{SMN_Endpoint}/v2/{project_id}/{resource_type}/resource_instances/action
  {
    "offset" : "100",
    "limit" : "100",
    "action" : "filter",
    "matches" : [ {
      "key" : "resource_name",
      "value" : "resource1"
    } ],
    "not_tags" : [ {
      "key" : "key1",
      "values" : [ "*value1", "value2" ]
    }, {
      "key" : "key2",
      "values" : [ "*value21", "value22" ]
    } ],
    "tags" : [ {
      "key" : "key1",
      "values" : [ "*value1", "value2" ]
    } ],
    "tags_any" : [ {
      "key" : "key1",
      "values" : [ "value1", "value2" ]
    } ],
    "not_tags_any" : [ {
      "key" : "key1",
      "values" : [ "value1", "value2" ]
    } ]
  }
  ```
  
- 使用标签查询资源实例总数
  ```
  POST https://{SMN_Endpoint}/v2/{project_id}/{resource_type}/resource_instances/action
  {
    "action" : "count",
    "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" ]
    } ],
    "matches" : [ {
      "key" : "resource_name",
      "value" : "resource"
    } ]
  }
  ```
  
 
#### 响应示例
**状态码：200**
```
{
  "resources" : [ {
    "resource_detail" : {
      "topic_urn" : "urn:smn:regionId:f96188c7ccaf4ffba0c9aa149ab2bd57:resource1",
      "display_name" : "testtest",
      "enterprise_project_id" : "0"
    },
    "resource_id" : "cffe4fc4c9a54219b60dbaf7b586e132",
    "resource_name" : "resource1",
    "tags" : [ {
      "key" : "key1",
      "value" : "value1"
    } ]
  } ],
  "total_count" : 1000
}
```
#### SDK代码示例
SDK代码示例如下。
- [Java]
  - 使用标签过滤资源实例
    ```
    package com.huaweicloud.sdk.test;
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.smn.v2.region.SmnRegion;
    import com.huaweicloud.sdk.smn.v2.*;
    import com.huaweicloud.sdk.smn.v2.model.*;
    import java.util.List;
    import java.util.ArrayList;
    public class ListResourceInstancesSolution {
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
            SmnClient client = SmnClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(SmnRegion.valueOf("<YOUR REGION>"))
                    .build();
            ListResourceInstancesRequest request = new ListResourceInstancesRequest();
            request.withResourceType("{resource_type}");
            ListInstanceRequestBody body = new ListInstanceRequestBody();
            List<TagMatch> listbodyMatches = new ArrayList<>();
            listbodyMatches.add(
                new TagMatch()
                    .withKey("resource_name")
                    .withValue("resource1")
            );
            List<String> listNotTagsAnyValues = new ArrayList<>();
            listNotTagsAnyValues.add("value1");
            listNotTagsAnyValues.add("value2");
            List<ResourceTags> listbodyNotTagsAny = new ArrayList<>();
            listbodyNotTagsAny.add(
                new ResourceTags()
                    .withKey("key1")
                    .withValues(listNotTagsAnyValues)
            );
            List<String> listNotTagsValues = new ArrayList<>();
            listNotTagsValues.add("*value21");
            listNotTagsValues.add("value22");
            List<String> listNotTagsValues1 = new ArrayList<>();
            listNotTagsValues1.add("*value1");
            listNotTagsValues1.add("value2");
            List<ResourceTags> listbodyNotTags = new ArrayList<>();
            listbodyNotTags.add(
                new ResourceTags()
                    .withKey("key1")
                    .withValues(listNotTagsValues1)
            );
            listbodyNotTags.add(
                new ResourceTags()
                    .withKey("key2")
                    .withValues(listNotTagsValues)
            );
            List<String> listTagsAnyValues = new ArrayList<>();
            listTagsAnyValues.add("value1");
            listTagsAnyValues.add("value2");
            List<ResourceTags> listbodyTagsAny = new ArrayList<>();
            listbodyTagsAny.add(
                new ResourceTags()
                    .withKey("key1")
                    .withValues(listTagsAnyValues)
            );
            List<String> listTagsValues = new ArrayList<>();
            listTagsValues.add("*value1");
            listTagsValues.add("value2");
            List<ResourceTags> listbodyTags = new ArrayList<>();
            listbodyTags.add(
                new ResourceTags()
                    .withKey("key1")
                    .withValues(listTagsValues)
            );
            body.withMatches(listbodyMatches);
            body.withAction("filter");
            body.withLimit("100");
            body.withOffset("100");
            body.withNotTagsAny(listbodyNotTagsAny);
            body.withNotTags(listbodyNotTags);
            body.withTagsAny(listbodyTagsAny);
            body.withTags(listbodyTags);
            request.withBody(body);
            try {
                ListResourceInstancesResponse response = client.listResourceInstances(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    ```
    
  
  - 使用标签查询资源实例总数
    ```
    package com.huaweicloud.sdk.test;
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.smn.v2.region.SmnRegion;
    import com.huaweicloud.sdk.smn.v2.*;
    import com.huaweicloud.sdk.smn.v2.model.*;
    import java.util.List;
    import java.util.ArrayList;
    public class ListResourceInstancesSolution {
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
            SmnClient client = SmnClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(SmnRegion.valueOf("<YOUR REGION>"))
                    .build();
            ListResourceInstancesRequest request = new ListResourceInstancesRequest();
            request.withResourceType("{resource_type}");
            ListInstanceRequestBody body = new ListInstanceRequestBody();
            List<TagMatch> listbodyMatches = new ArrayList<>();
            listbodyMatches.add(
                new TagMatch()
                    .withKey("resource_name")
                    .withValue("resource")
            );
            List<String> listNotTagsAnyValues = new ArrayList<>();
            listNotTagsAnyValues.add("value1");
            listNotTagsAnyValues.add("value2");
            List<ResourceTags> listbodyNotTagsAny = new ArrayList<>();
            listbodyNotTagsAny.add(
                new ResourceTags()
                    .withKey("key1")
                    .withValues(listNotTagsAnyValues)
            );
            List<String> listNotTagsValues = new ArrayList<>();
            listNotTagsValues.add("value1");
            listNotTagsValues.add("*value2");
            List<ResourceTags> listbodyNotTags = new ArrayList<>();
            listbodyNotTags.add(
                new ResourceTags()
                    .withKey("key1")
                    .withValues(listNotTagsValues)
            );
            List<String> listTagsAnyValues = new ArrayList<>();
            listTagsAnyValues.add("value1");
            listTagsAnyValues.add("value2");
            List<ResourceTags> listbodyTagsAny = new ArrayList<>();
            listbodyTagsAny.add(
                new ResourceTags()
                    .withKey("key1")
                    .withValues(listTagsAnyValues)
            );
            List<String> listTagsValues = new ArrayList<>();
            listTagsValues.add("value1");
            listTagsValues.add("value2");
            List<ResourceTags> listbodyTags = new ArrayList<>();
            listbodyTags.add(
                new ResourceTags()
                    .withKey("key1")
                    .withValues(listTagsValues)
            );
            body.withMatches(listbodyMatches);
            body.withAction("count");
            body.withNotTagsAny(listbodyNotTagsAny);
            body.withNotTags(listbodyNotTags);
            body.withTagsAny(listbodyTagsAny);
            body.withTags(listbodyTags);
            request.withBody(body);
            try {
                ListResourceInstancesResponse response = client.listResourceInstances(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    ```
    
   
- [Python]
  - 使用标签过滤资源实例
    ```
    # coding: utf-8
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdksmn.v2.region.smn_region import SmnRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdksmn.v2 import *
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
        credentials = BasicCredentials(ak, sk, projectId)
        client = SmnClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(SmnRegion.value_of("<YOUR REGION>")) \
            .build()
        try:
            request = ListResourceInstancesRequest()
            request.resource_type = "{resource_type}"
            listMatchesbody = [
                TagMatch(
                    key="resource_name",
                    value="resource1"
                )
            ]
            listValuesNotTagsAny = [
                "value1",
                "value2"
            ]
            listNotTagsAnybody = [
                ResourceTags(
                    key="key1",
                    values=listValuesNotTagsAny
                )
            ]
            listValuesNotTags = [
                "*value21",
                "value22"
            ]
            listValuesNotTags1 = [
                "*value1",
                "value2"
            ]
            listNotTagsbody = [
                ResourceTags(
                    key="key1",
                    values=listValuesNotTags1
                ),
                ResourceTags(
                    key="key2",
                    values=listValuesNotTags
                )
            ]
            listValuesTagsAny = [
                "value1",
                "value2"
            ]
            listTagsAnybody = [
                ResourceTags(
                    key="key1",
                    values=listValuesTagsAny
                )
            ]
            listValuesTags = [
                "*value1",
                "value2"
            ]
            listTagsbody = [
                ResourceTags(
                    key="key1",
                    values=listValuesTags
                )
            ]
            request.body = ListInstanceRequestBody(
                matches=listMatchesbody,
                action="filter",
                limit="100",
                offset="100",
                not_tags_any=listNotTagsAnybody,
                not_tags=listNotTagsbody,
                tags_any=listTagsAnybody,
                tags=listTagsbody
            )
            response = client.list_resource_instances(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    ```
    
  
  - 使用标签查询资源实例总数
    ```
    # coding: utf-8
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdksmn.v2.region.smn_region import SmnRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdksmn.v2 import *
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
        credentials = BasicCredentials(ak, sk, projectId)
        client = SmnClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(SmnRegion.value_of("<YOUR REGION>")) \
            .build()
        try:
            request = ListResourceInstancesRequest()
            request.resource_type = "{resource_type}"
            listMatchesbody = [
                TagMatch(
                    key="resource_name",
                    value="resource"
                )
            ]
            listValuesNotTagsAny = [
                "value1",
                "value2"
            ]
            listNotTagsAnybody = [
                ResourceTags(
                    key="key1",
                    values=listValuesNotTagsAny
                )
            ]
            listValuesNotTags = [
                "value1",
                "*value2"
            ]
            listNotTagsbody = [
                ResourceTags(
                    key="key1",
                    values=listValuesNotTags
                )
            ]
            listValuesTagsAny = [
                "value1",
                "value2"
            ]
            listTagsAnybody = [
                ResourceTags(
                    key="key1",
                    values=listValuesTagsAny
                )
            ]
            listValuesTags = [
                "value1",
                "value2"
            ]
            listTagsbody = [
                ResourceTags(
                    key="key1",
                    values=listValuesTags
                )
            ]
            request.body = ListInstanceRequestBody(
                matches=listMatchesbody,
                action="count",
                not_tags_any=listNotTagsAnybody,
                not_tags=listNotTagsbody,
                tags_any=listTagsAnybody,
                tags=listTagsbody
            )
            response = client.list_resource_instances(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    ```
    
   
- [Go]
  - 使用标签过滤资源实例
    ```
    package main
    import (
    "fmt"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        smn "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/smn/v2"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/smn/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/smn/v2/region"
    )
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
        auth, err := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            SafeBuild()
        if err != nil {
            fmt.Println(err)
            return
        }
        hcClient, err := smn.SmnClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
        if err != nil {
            fmt.Println(err)
            return
        }
        client := smn.NewSmnClient(hcClient)
        request := &model.ListResourceInstancesRequest{}
    request.ResourceType = "{resource_type}"
    var listMatchesbody = []model.TagMatch{
            {
                Key: "resource_name",
                Value: "resource1",
            },
        }
    var listValuesNotTagsAny = []string{
            "value1",
        "value2",
        }
    var listNotTagsAnybody = []model.ResourceTags{
            {
                Key: "key1",
                Values: listValuesNotTagsAny,
            },
        }
    var listValuesNotTags = []string{
            "*value21",
        "value22",
        }
    var listValuesNotTags1 = []string{
            "*value1",
        "value2",
        }
    var listNotTagsbody = []model.ResourceTags{
            {
                Key: "key1",
                Values: listValuesNotTags1,
            },
            {
                Key: "key2",
                Values: listValuesNotTags,
            },
        }
    var listValuesTagsAny = []string{
            "value1",
        "value2",
        }
    var listTagsAnybody = []model.ResourceTags{
            {
                Key: "key1",
                Values: listValuesTagsAny,
            },
        }
    var listValuesTags = []string{
            "*value1",
        "value2",
        }
    var listTagsbody = []model.ResourceTags{
            {
                Key: "key1",
                Values: listValuesTags,
            },
        }
    limitListInstanceRequestBody:= "100"
    offsetListInstanceRequestBody:= "100"
    request.Body = &model.ListInstanceRequestBody{
    Matches: &listMatchesbody,
    Action: "filter",
    Limit: &limitListInstanceRequestBody,
    Offset: &offsetListInstanceRequestBody,
    NotTagsAny: &listNotTagsAnybody,
    NotTags: &listNotTagsbody,
    TagsAny: &listTagsAnybody,
    Tags: &listTagsbody,
    }
    response, err := client.ListResourceInstances(request)
    if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    ```
    
  
  - 使用标签查询资源实例总数
    ```
    package main
    import (
    "fmt"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        smn "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/smn/v2"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/smn/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/smn/v2/region"
    )
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
        auth, err := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            SafeBuild()
        if err != nil {
            fmt.Println(err)
            return
        }
        hcClient, err := smn.SmnClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
        if err != nil {
            fmt.Println(err)
            return
        }
        client := smn.NewSmnClient(hcClient)
        request := &model.ListResourceInstancesRequest{}
    request.ResourceType = "{resource_type}"
    var listMatchesbody = []model.TagMatch{
            {
                Key: "resource_name",
                Value: "resource",
            },
        }
    var listValuesNotTagsAny = []string{
            "value1",
        "value2",
        }
    var listNotTagsAnybody = []model.ResourceTags{
            {
                Key: "key1",
                Values: listValuesNotTagsAny,
            },
        }
    var listValuesNotTags = []string{
            "value1",
        "*value2",
        }
    var listNotTagsbody = []model.ResourceTags{
            {
                Key: "key1",
                Values: listValuesNotTags,
            },
        }
    var listValuesTagsAny = []string{
            "value1",
        "value2",
        }
    var listTagsAnybody = []model.ResourceTags{
            {
                Key: "key1",
                Values: listValuesTagsAny,
            },
        }
    var listValuesTags = []string{
            "value1",
        "value2",
        }
    var listTagsbody = []model.ResourceTags{
            {
                Key: "key1",
                Values: listValuesTags,
            },
        }
    request.Body = &model.ListInstanceRequestBody{
    Matches: &listMatchesbody,
    Action: "count",
    NotTagsAny: &listNotTagsAnybody,
    NotTags: &listNotTagsbody,
    TagsAny: &listTagsAnybody,
    Tags: &listTagsbody,
    }
    response, err := client.ListResourceInstances(request)
    if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    ```
    
   
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/SMN/sdk?api=ListResourceInstances&version=v2)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述                    |
|:---|:---|
| 200 | OK                    |
| 400 | Bad Request           |
| 403 | Unauthorized          |
| 404 | Not Found             |
| 500 | Internal Server Error |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-smn/ErrorCode.html)。
