> 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/zec/vnic/createnetworkinterfacepermission.md).

# CreateNetworkInterfacePermission

## 1. 接口描述

本接口(CreateNetworkInterfacePermission)用于授权其他账号把一张网卡绑定到它自己的实例上。

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

* 授权后，被授权账号可以调用 [AttachNetworkInterface](https://docs.console.zenlayer.com/api-reference/cn/zec/vnic/attachnetworkinterface.md) 把网卡绑定到它自己的实例上；网卡仍属于当前账号。
* 授权只是允许绑定，不会立即绑定网卡；撤销授权调用 [DeleteNetworkInterfacePermission](https://docs.console.zenlayer.com/api-reference/cn/zec/vnic/deletenetworkinterfacepermission.md)。
  {% endhint %}

## 2. 请求参数

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

| 参数名称       | 必选 | 类型                                                                                                     | 描述                                                                                                                                                                                                            |
| ---------- | -- | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| nicId      | 是  | String                                                                                                 | <p>要授权的网卡ID。</p><p>可通过调用 <a href="https://docs.console.zenlayer.com/api-reference/cn/zec/vnic/describenetworkinterfaces.md">DescribeNetworkInterfaces</a> 获取。</p><p>不支持主网卡，网卡状态须为 <code>AVAILABLE</code>。</p> |
| granteeCid | 是  | String                                                                                                 | <p>被授权账号的cid，不能是网卡所属账号。</p><p>一张网卡只能授权给一个账号；对同一账号重复授权同一操作时，返回已有的授权。</p>                                                                                                                                       |
| permission | 是  | [NicPermission](https://docs.console.zenlayer.com/api-reference/cn/zec/datastructure.md#nicpermission) | 授权的操作。                                                                                                                                                                                                        |

## 3. 响应结果

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

## 4. 代码示例

{% tabs %}
{% tab title="示例" %}
**1. 授权其他账号绑定网卡。**

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

Request：
{
  "nicId": "<nicId>",
  "granteeCid": "<granteeCid>",
  "permission": "INSTANCE_ATTACH"
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "permissionId": "<permissionId>"
  }
}
```

{% endtab %}
{% endtabs %}

## 5. 开发者工具

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

## 6. 错误码

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

| HTTP状态码 | 错误码                                           | 说明                      |
| ------- | --------------------------------------------- | ----------------------- |
| 404     | INVALID\_NIC\_NOT\_FOUND                      | 网卡不存在。                  |
| 400     | INVALID\_NIC\_STATUS                          | 当前网卡状态无法进行操作。           |
| 404     | INVALID\_NIC\_PERMISSION\_GRANTEE\_NOT\_FOUND | 被授权的账号不存在。              |
| 400     | INVALID\_NIC\_PERMISSION\_GRANTEE\_SELF       | 网卡不能授权给它自己所属的账号。        |
| 400     | OPERATION\_DENIED\_NIC\_PERMISSION\_EXISTS    | 一张网卡只能授权给一个账号，已授权给其他账号。 |
| 400     | UNSUPPORTED\_OPERATION\_NIC\_IS\_PRIMARY      | 不支持对主网卡进行此操作。           |
