> For the complete documentation index, see [llms.txt](https://docs.console.zenlayer.com/api-reference/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.console.zenlayer.com/api-reference/cn/sdn/private-connect/describeprivateconnecttraffic.md).

# DescribePrivateConnectTraffic

## 1. 接口描述

本接口(DescribePrivateConnectTraffic)用于查询二层网络专线流量。

{% hint style="info" %}
**注意事项**

* 开始时间和结束时间的跨度不能超过一天。
* 只能查询30天内的流量数据。
  {% endhint %}

## 2. 请求参数

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

| 参数名称             | 必选 | 类型                                                                          | 描述                                                                                                                                            |
| ---------------- | -- | --------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| privateConnectId | 是  | String                                                                      | 二层网络专线 ID。                                                                                                                                    |
| startTime        | 是  | String                                                                      | <p>查询开始时间。</p><p>ISO8601 UTC 格式：YYYY-MM-DDThh<span data-gb-custom-inline data-tag="emoji" data-code="1f1f2-1f1f2">🇲🇲</span>ssZ。</p>         |
| endTime          | 否  | String                                                                      | <p>查询结束时间。</p><p>ISO8601 UTC 格式：YYYY-MM-DDThh<span data-gb-custom-inline data-tag="emoji" data-code="1f1f2-1f1f2">🇲🇲</span>ssZ，默认为当前时间。</p> |
| period           | 否  | Integer                                                                     | <p>数据采样周期。</p><p>单位为秒，可选值：20、40、60、120、300、900。</p><p>默认值：300</p>                                                                             |
| statistic        | 否  | [TrafficStatistic](/api-reference/cn/sdn/datastructure.md#trafficstatistic) | <p>采样周期内流量数据的统计方式。</p><p>默认值：Average</p>                                                                                                      |

## 3. 响应结果

| 参数名称      | 类型                                                                         | 描述                                                       |
| --------- | -------------------------------------------------------------------------- | -------------------------------------------------------- |
| requestId | String                                                                     | <p>唯一请求 ID。</p><p>每次请求都会返回。定位问题时需要提供该次请求的 requestId。</p> |
| dataList  | Array of [TrafficData](/api-reference/cn/sdn/datastructure.md#trafficdata) | 流量明细数据列表。                                                |
| in95      | Integer                                                                    | 入方向 95 峰值流量。                                             |
| inAvg     | Integer                                                                    | 入方向平均流量。                                                 |
| inMax     | Integer                                                                    | 入方向最大流量。                                                 |
| inMin     | Integer                                                                    | 入方向最小流量。                                                 |
| out95     | Integer                                                                    | 出方向 95 峰值流量。                                             |
| outAvg    | Integer                                                                    | 出方向平均流量。                                                 |
| outMax    | Integer                                                                    | 出方向最大流量。                                                 |
| outMin    | Integer                                                                    | 出方向最小流量。                                                 |
| unit      | String                                                                     | <p>流量单位。</p><p>如 bps。</p>                                |

## 4. 代码示例

{% tabs %}
{% tab title="示例" %}

1. **查询实例一天内的流量数据。**

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

Request:
{
  "privateConnectId": "your-private-connect-id",
  "startTime": "2023-01-01T00:00:00Z",
  "endTime": "2023-01-01T23:59:59Z"
}

Response:
{
  "requestId": "T4C35327C-7B13-47B8-A815-5E5213D4A9F9",
  "response": {
    "requestId": "T4C35327C-7B13-47B8-A815-5E5213D4A9F9",
    "dataList": [
      {
        "internetRX": 873034,
        "internetTX": 11971,
        "time": "2023-01-01T00:00:00Z"
      },
      {
        "internetRX": 873034,
        "internetTX": 11971,
        "time": "2023-01-01T00:05:00Z"
      },
      {
        "internetRX": 635218,
        "internetTX": 9028,
        "time": "2023-01-01T00:10:00Z"
      }
    ],
    "in95": 873034,
    "inAvg": 793762,
    "inMax": 873034,
    "inMin": 635218,
    "out95": 11971,
    "outAvg": 10990,
    "outMax": 11971,
    "outMin": 9028,
    "unit": "bps"
  }
}
```

2. **以 1 分钟为采样周期，查询实例一小时内每分钟的最大流量。**

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

Request:
{
  "privateConnectId": "your-private-connect-id",
  "startTime": "2026-01-01T00:00:00Z",
  "endTime": "2026-01-01T01:00:00Z",
  "period": 60,
  "statistic": "Maximum"
}

Response:
{
  "requestId": "T4C35327C-7B13-47B8-A815-5E5213D4A9F9",
  "response": {
    "requestId": "T4C35327C-7B13-47B8-A815-5E5213D4A9F9",
    "dataList": [
      {
        "internetRX": 912480,
        "internetTX": 12630,
        "time": "2026-01-01T00:00:00Z"
      },
      {
        "internetRX": 887215,
        "internetTX": 12104,
        "time": "2026-01-01T00:01:00Z"
      },
      {
        "internetRX": 701336,
        "internetTX": 9875,
        "time": "2026-01-01T00:02:00Z"
      }
    ],
    "in95": 912480,
    "inAvg": 833677,
    "inMax": 912480,
    "inMin": 701336,
    "out95": 12630,
    "outAvg": 11536,
    "outMax": 12630,
    "outMin": 9875,
    "unit": "bps"
  }
}
```

{% endtab %}
{% endtabs %}

## 5. 开发者工具

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

## 6. 错误码

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

| HTTP状态码 | 错误码                                             | 说明            |
| ------- | ----------------------------------------------- | ------------- |
| 404     | INVALID\_PRIVATE\_CONNECT\_NOT\_FOUND           | 二层网络专线不存在。    |
| 400     | INVALID\_TRAFFIC\_START\_TIME\_AFTER\_END\_TIME | 开始时间必须早于结束时间。 |
| 400     | INVALID\_TRAFFIC\_TIME\_RANGE                   | 查询时间范围无效。     |
