# DescribeInstances

## 1. 接口描述

本接口(DescribeInstances)用于查询一台或多台虚拟机实例的信息。用户可以根据实例ID、实例名称等条件来查询实例的详细信息。

## 2. 请求参数

以下请求参数列表仅列出了接口中需要的请求参数

| 参数名称            | 必选 | 类型                                                                                                        | 描述                                     |
| --------------- | -- | --------------------------------------------------------------------------------------------------------- | -------------------------------------- |
| instanceIds     | 否  | Array of String                                                                                           | <p>根据实例ID列表进行筛选。</p><p>最大不能超过100个。</p> |
| zoneId          | 否  | String                                                                                                    | 实例所属的可用区ID。                            |
| imageId         | 否  | String                                                                                                    | 镜像ID。                                  |
| ipv4Address     | 否  | String                                                                                                    | 根据实例关联的IPv4过滤。                         |
| ipv6Address     | 否  | String                                                                                                    | 根据实例关联的IPv6信息过滤。                       |
| status          | 否  | [InstanceStatusValue](https://docs.console.zenlayer.com/api/cn/compute/datastructure#instancestatusvalue) | 根据实例的状态过滤。                             |
| name            | 否  | String                                                                                                    | <p>根据实例显示名称过滤。</p><p>该字段支持模糊搜索。</p>    |
| pageSize        | 否  | Integer                                                                                                   | <p>返回的分页大小。</p><p>默认值：20。</p>          |
| pageNum         | 否  | Integer                                                                                                   | 返回的分页数。                                |
| resourceGroupId | 否  | String                                                                                                    | 根据资源组ID过滤。                             |

## 3. 响应结果

| 参数名称       | 类型                                                                                                   | 描述                                                       |
| ---------- | ---------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
| requestId  | String                                                                                               | <p>唯一请求 ID。</p><p>每次请求都会返回。定位问题时需要提供该次请求的 requestId。</p> |
| totalCount | Integer                                                                                              | 符合条件的数据总数。                                               |
| dataSet    | Array of [InstanceInfo](https://docs.console.zenlayer.com/api/cn/compute/datastructure#instanceinfo) | 实例列表的数据。                                                 |

## 4. 代码示例

{% tabs %}
{% tab title="示例" %}
**1. 查询虚拟机实例列表**

```json
POST /api/v2/zec HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: DescribeInstances
<Common Request Params>

Request:
{
  "instanceIds": ["xxx"],
  "pageSize": 10,
  "pageNum": 1
}

Response:
{
  "requestId": "TFA4FD1A1-41B6-4BA7-A408-1D654A3E0D36",
  "response": {
      "requestId": "TFA4FD1A1-41B6-4BA7-A408-1D654A3E0D36",
      "totalCount": 1,
      "dataSet": [
          {
              "subnetId": "<subnetId>",
              "memory": 2,
              "instanceName": "instance",
              "enableIpForward": true,
              "keyId": "key-7K9AcYWv",
              "securityGroupId": "<securityGroupId>",
              "instanceId": "<instanceId>",
              "nics": [
                  {
                      "subnetId": "<subnetId>",
                      "resourceGroup": {
                          "resourceGroupName": "Default Resource Group",
                          "resourceGroupId": "<resourceGroupId>"
                      },
                      "primaryIpv4": "10.130.0.2",
                      "privateIpList": ["10.130.0.2"],
                      "nicSubnetType": "IPv4",
                      "updateTime": "2025-07-16T01:26:39Z",
                      "primaryIpv6": null,
                      "publicIpList": [],
                      "securityGroupId": "<securityGroupId>",
                      "ipv6Cidr": null,
                      "macAddress": "52:54:00:2f:a7:ec",
                      "instanceId": "<instanceId>",
                      "regionId": "asia-east-1",
                      "createTime": "2025-07-16T01:26:39Z",
                      "nicType": "Primary",
                      "vpcId": "<vpcId>",
                      "name": "Primary-Nic-asia-east-1-01",
                      "nicId": "<nicId>",
                      "status": "USED",
                      "secondaryIpv4s": []
                  }
              ],
              "zoneId": "asia-east-1a",
              "resourceGroupId": "<resourceGroupId>",
              "nicNetworkType": "VirtioOnly",
              "privateIpAddresses": ["10.130.0.2"],
              "imageId": "<imageId>",
              "imageName": "<imageName>",
              "resourceGroupName": "Default Resource Group",
              "systemDisk": {
                  "diskSize": 20,
                  "diskId": "<diskId>",
                  "diskCategory": "<diskCategory>"
              },
              "instanceType": "z2a.cpu.1",
              "cpu": 1,
              "timeZone": "Asia/Shanghai",
              "enableAgent": true,
              "expiredTime": null,
              "publicIpAddresses": ["128.0.0.2"],
              "createTime": "2025-05-01T01:01:01Z",
              "dataDisks": null,
              "enableAgentMonitor": true,
              "status": "RUNNING"
          }
      ]
  }
}
```

{% endtab %}
{% endtabs %}

## 5. 开发者工具

Zenlayer Cloud API 2.0 提供了配套的[开发工具集（SDK）](https://docs.console.zenlayer.com/api/cn/api-introduction/toolkit)，未来会陆续支持更多开发语言，方便快速接入和使用Zenlayer的产品和服务。

## 6. 错误码

下面包含业务逻辑中遇到的错误码，其他错误码见[公共错误码](https://docs.console.zenlayer.com/api/cn/api-introduction/instruction/commonerrorcode)

| HTTP状态码 | 错误码 | 说明 |
| ------- | --- | -- |
