
# 根据标签查询CA数量 - CountCaResourceInstances
#### 功能介绍
根据标签查询CA数量。
#### 调试
您可以在[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/CCM/doc?api=CountCaResourceInstances)中调试该接口，支持自动认证鉴权。API Explorer可以自动生成SDK代码示例，并提供SDK代码示例调试功能。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-ccm/ccm_02_0039.html)。
- 如果使用身份策略授权，当前API调用无需身份策略权限。
 
#### URI
POST /v1/private-certificate-authorities/resource-instances/count
#### 请求参数
表1请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                       |
|:---|:---|:---|:---|
| X-Auth-Token | 是    | String | 用户Token。通过调用IAM服务获取用户Token接口获取（响应消息头中X-Subject-Token的值）。 |
   
表2请求Body参数 
| 参数      | 是否必选 | 参数类型                                                                           | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
|:---|:---|:---|:---|
| tags    | 否    | Array of [DomainTags] objects   | 标签列表。 最多包含20个key，每个key下面的value最多20个，每个key对应的value可以为空数组但结构体不能缺失。key不能重复，同一个key中values不能重复。结果返回包含所有标签的资源列表，key之间是与的关系，key-value结构中value是或的关系。无tag过滤条件时返回全量数据。 数组长度：**1 - 20**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| limit   | 否    | Integer                                                                        | 每页条目数量，取值如下： - 10：每页显示10条资源信息。   - 20：每页显示20条资源信息。   - 50：每页显示50条资源信息。    最小值：**10** 最大值：**50** 缺省值：**10** |
| offset  | 否    | Integer                                                                        | 索引位置，偏移量，从offset指定的下一条数据开始查询。 最小值：**0** 缺省值：**0**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| matches | 否    | Array of [ResourceTag] objects | 搜索字段。 key为要匹配的字段，如resource_name等。value为匹配的值。key为固定字典值，不能包含重复的key或不支持的key。 数组长度：**0 - 20**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
   
 表3DomainTags 
| 参数     | 是否必选 | 参数类型             | 描述                                                                                                                                                                                                                                                                                            |
|:---|:---|:---|:---|
| key    | 是    | String           | 标签键。 可用 UTF-8 格式表示的字母(包含中文、西班牙语、葡语等)、数字和空格，以及以下字符： _ . : = + - @ 最小长度：**1** 最大长度：**128**                                                                  |
| values | 是    | Array of strings | 标签值列表。 每个值可用 UTF-8 格式表示的字母(包含中文、西班牙语、葡语等)、数字和空格，以及以下字符： _ . : = + - @ 最小长度：**0** 最大长度：**255** 数组长度：**1 - 20** |
   
 表4ResourceTag 
| 参数    | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                             |
|:---|:---|:---|:---|
| key   | 是    | String | 标签键。 可用 UTF-8 格式表示的字母(包含中文、西班牙语、葡语等)、数字和空格，以及以下字符： _ . : = + - @ 最小长度：**1** 最大长度：**128**   |
| value | 是    | String | 标签值。 可用 UTF-8 格式表示的字母(包含中文、西班牙语、葡语等)、数字和空格，以及以下字符： _ . : / = + - @ 最小长度：**0** 最大长度：**255** |
   
#### 响应参数
**状态码：200**
表5响应Body参数 
| 参数          | 参数类型    | 描述                                                                                                                  |
|:---|:---|:---|
| total_count | Integer | 总记录数。 最小值：**0** 最大值：**100** |
   
**状态码：400**
表6响应Body参数 
| 参数         | 参数类型   | 描述                                                                                                                            |
|:---|:---|:---|
| error_code | String | 错误请求返回的错误码。 最小长度：**3** 最大长度：**36**    |
| error_msg  | String | 错误请求返回的错误信息。 最小长度：**0** 最大长度：**1024** |
   
**状态码：401**
表7响应Body参数 
| 参数         | 参数类型   | 描述                                                                                                                            |
|:---|:---|:---|
| error_code | String | 错误请求返回的错误码。 最小长度：**3** 最大长度：**36**    |
| error_msg  | String | 错误请求返回的错误信息。 最小长度：**0** 最大长度：**1024** |
   
**状态码：403**
表8响应Body参数 
| 参数         | 参数类型   | 描述                                                                                                                            |
|:---|:---|:---|
| error_code | String | 错误请求返回的错误码。 最小长度：**3** 最大长度：**36**    |
| error_msg  | String | 错误请求返回的错误信息。 最小长度：**0** 最大长度：**1024** |
   
**状态码：404**
表9响应Body参数 
| 参数         | 参数类型   | 描述                                                                                                                            |
|:---|:---|:---|
| error_code | String | 错误请求返回的错误码。 最小长度：**3** 最大长度：**36**    |
| error_msg  | String | 错误请求返回的错误信息。 最小长度：**0** 最大长度：**1024** |
   
**状态码：500**
表10响应Body参数 
| 参数         | 参数类型   | 描述                                                                                                                            |
|:---|:---|:---|
| error_code | String | 错误请求返回的错误码。 最小长度：**3** 最大长度：**36**    |
| error_msg  | String | 错误请求返回的错误信息。 最小长度：**0** 最大长度：**1024** |
   
#### 请求示例
根据标签查询CA数量，请求头中的**X-Auth-Token**字段需要填写token，且该token需要具有本API的访问权限。
```
POST https://ccm.cn-north-4.myhuaweicloud.com/v1/private-certificate-authorities/resource-instances/count
{
  "tags" : [ {
    "key" : "key1",
    "values" : [ "value1", "value2" ]
  } ]
}
```
#### 响应示例
**状态码：200**
请求已成功
```
{
  "total_count" : 1
}
```
**状态码：400**
请求参数有误。
```
{
  "error_code" : "PCA.XXX",
  "error_msg" : "XXX"
}
```
**状态码：401**
被请求的页面需要鉴权。
```
{
  "error_code" : "PCA.XXX",
  "error_msg" : "XXX"
}
```
**状态码：403**
认证失败。
```
{
  "error_code" : "PCA.XXX",
  "error_msg" : "XXX"
}
```
**状态码：404**
资源不存在或资源未找到。
```
{
  "error_code" : "PCA.XXX",
  "error_msg" : "XXX"
}
```
**状态码：500**
服务内部错误。
```
{
  "error_code" : "PCA.XXX",
  "error_msg" : "XXX"
}
```
#### SDK代码示例
SDK代码示例如下。
#### Java
根据标签查询CA数量，请求头中的**X-Auth-Token**字段需要填写token，且该token需要具有本API的访问权限。
```
package com.huaweicloud.sdk.test;
import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.GlobalCredentials;
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.ccm.v1.region.CcmRegion;
import com.huaweicloud.sdk.ccm.v1.*;
import com.huaweicloud.sdk.ccm.v1.model.*;
import java.util.List;
import java.util.ArrayList;
public class CountCaResourceInstancesSolution {
    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");
        ICredential auth = new GlobalCredentials()
                .withAk(ak)
                .withSk(sk);
        CcmClient client = CcmClient.newBuilder()
                .withCredential(auth)
                .withRegion(CcmRegion.valueOf("<YOUR REGION>"))
                .build();
        CountCaResourceInstancesRequest request = new CountCaResourceInstancesRequest();
        ListResourceInstancesRequestBody body = new ListResourceInstancesRequestBody();
        List<String> listTagsValues = new ArrayList<>();
        listTagsValues.add("value1");
        listTagsValues.add("value2");
        List<DomainTags> listbodyTags = new ArrayList<>();
        listbodyTags.add(
            new DomainTags()
                .withKey("key1")
                .withValues(listTagsValues)
        );
        body.withTags(listbodyTags);
        request.withBody(body);
        try {
            CountCaResourceInstancesResponse response = client.countCaResourceInstances(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
根据标签查询CA数量，请求头中的**X-Auth-Token**字段需要填写token，且该token需要具有本API的访问权限。
```
# coding: utf-8
import os
from huaweicloudsdkcore.auth.credentials import GlobalCredentials
from huaweicloudsdkccm.v1.region.ccm_region import CcmRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkccm.v1 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"]
    credentials = GlobalCredentials(ak, sk)
    client = CcmClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CcmRegion.value_of("<YOUR REGION>")) \
        .build()
    try:
        request = CountCaResourceInstancesRequest()
        listValuesTags = [
            "value1",
            "value2"
        ]
        listTagsbody = [
            DomainTags(
                key="key1",
                values=listValuesTags
            )
        ]
        request.body = ListResourceInstancesRequestBody(
            tags=listTagsbody
        )
        response = client.count_ca_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
根据标签查询CA数量，请求头中的**X-Auth-Token**字段需要填写token，且该token需要具有本API的访问权限。
```
package main
import (
"fmt"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
    ccm "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ccm/v1"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ccm/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ccm/v1/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")
    auth, err := global.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        SafeBuild()
    if err != nil {
        fmt.Println(err)
        return
    }
    hcClient, err := ccm.CcmClientBuilder().
         WithRegion(region.ValueOf("<YOUR REGION>")).
         WithCredential(auth).
         SafeBuild()
    if err != nil {
        fmt.Println(err)
        return
    }
    client := ccm.NewCcmClient(hcClient)
    request := &model.CountCaResourceInstancesRequest{}
var listValuesTags = []string{
        "value1",
    "value2",
    }
var listTagsbody = []model.DomainTags{
        {
            Key: "key1",
            Values: listValuesTags,
        },
    }
request.Body = &model.ListResourceInstancesRequestBody{
Tags: &listTagsbody,
}
response, err := client.CountCaResourceInstances(request)
if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}
```
#### 更多
更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/CCM/sdk?api=CountCaResourceInstances)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述           |
|:---|:---|
| 200 | 请求已成功        |
| 400 | 请求参数有误。      |
| 401 | 被请求的页面需要鉴权。  |
| 403 | 认证失败。        |
| 404 | 资源不存在或资源未找到。 |
| 500 | 服务内部错误。      |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-ccm/ErrorCode.html)。
