# CreatePort

## 1. 接口描述

本接口用于创建一个数据中心端口。

#### 准备工作

* 在创建Port之前，你可以调用[DescribeDatacenters](https://docs.console.zenlayer.com/api-reference/cn/networking/common/describedatacenters#describedatacenters)进行查看哪些数据中心支持端口的创建。

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

* 本接口为异步接口，当创建Port请求下发成功后会返回一个Port`ID`列表，此时创建Port操作并未立即完成。在此期间Port的状态将会处于\*\*`CREATING`**，Port创建结果可以通过调用**[**DescribePorts**](https://docs.console.zenlayer.com/api-reference/cn/networking/sdn/describeports#describeports)**接口查询，如果Port状态由**`CREATING`**(创建中)变为**`RUNNING`\*\*，则代表Port创建成功，否则代表还在创建中。创建过程中不可对Port进行任何操作。
  {% endhint %}

## 2. 请求参数

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

<table><thead><tr><th width="181">参数名称</th><th width="92">是否必选</th><th width="113">类型</th><th>描述</th></tr></thead><tbody><tr><td>dcId</td><td>是</td><td>String</td><td><p>数据中心四字码。</p><p>具体取值可通过调用接口<a href="../common/describedatacenters"><code>DescribeDataCenters</code></a>来获得最新的数据中心列表。</p></td></tr><tr><td>portName</td><td>是</td><td>String</td><td><p>端口名称。</p><p>最长不超过255个字符，建议使用数据中心四字码 + 端口规格拼接。</p></td></tr><tr><td>portRemarks</td><td>否</td><td>String</td><td><p>端口备注信息。</p><p>最长不超过255个字符。</p></td></tr><tr><td>portType</td><td>是</td><td>String</td><td><p>端口规格。</p><p>具体取值可通过调用接口<a href="describedatacenterportprice"><code>DescribeDataCenterPortType</code></a>来获得最新的端口规格表。</p></td></tr><tr><td>businessEntityName</td><td>是</td><td>String</td><td><p>贵司商业实体名称。</p><p>主要用于LOA（Letter of Authorization）的抬头。</p></td></tr><tr><td>marketingOptions</td><td>否</td><td><a href="../../datastructure#marketingoptions">MarketingOptions</a></td><td>市场营销活动相关信息。</td></tr><tr><td>tags</td><td>否</td><td><a href="../../datastructure#tagassociation">TagAssociation</a></td><td><p>创建端口时关联的标签。</p><p>注意：关联<code>标签键</code>不能重复。</p></td></tr></tbody></table>

## 3. 响应结果

| 参数名称      | 类型     | 描述                                                       |
| --------- | ------ | -------------------------------------------------------- |
| requestId | String | <p>唯一请求 ID。</p><p>每次请求都会返回。定位问题时需要提供该次请求的 requestId。</p> |
| portId    | String | 端口id。                                                    |

## 4. 代码示例

{% tabs %}
{% tab title="示例" %}
**1.在新加坡1（SIN1）创建一个1G规格的端口。**

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

Request:
{
  "dcId": "SIN1",
  "portName": "your-port-name",
  "portRemarks": "your-port-remarks",
  "portType": "1G",
  "businessEntityName": "your-business-entity-name"
}

Response:
{
  "requestId": "T3811A0E7-C250-40A2-96AD-08AD759E1BC2",
  "response": {
    "requestId": "T3811A0E7-C250-40A2-96AD-08AD759E1BC2",
    "portId": "your-port-id"
  }
}
```

{% endtab %}
{% endtabs %}

## 5. 开发者工具

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

## 6. 错误码

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

| HTTP状态码 | 错误码                             | 说明              |
| ------- | ------------------------------- | --------------- |
| 7111    | SELF\_SERVICE\_PORT\_NOT\_SHELF | 端口SKU未上架，暂不可购买。 |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/api-reference/cn/networking/sdn/port/createport.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
