> 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/zec/elastic-ip/associateeipaddress.md).

# AssociateEipAddress

## 1. API Description

This API (AssociateEipAddress) is used to associate elastic IPs to resources in the same region.

{% hint style="info" %}
**Notes**

* You can call [DescribeLoadBalancers](/api-reference/zlb/load-balancer-instance/describeloadbalancers.md) to view the load balancer instances that can be bound.
* You can call [DescribeNetworkInterfaces](/api-reference/zec/vnic/describenetworkinterfaces.md) to view the virtual network interfaces that can be bound.
* You can call [DescribeNatGateways](/api-reference/zec/nat-gateway/describenatgateways.md) to view the NAT gateways that can be bound.
* You can call [DescribeHaVips](/api-reference/zec/vpc-network/havip/describehavips.md) to view the high availability virtual IPs that can be bound.
* One of the parameters `loadBalancerId`, `nicId`, `natId`, and `haVipId` must be specified. If multiple fields are specified at the same time, they are used in the priority order of `loadBalancerId`, `nicId`, `natId`, and `haVipId`.
* When a load balancer instance is bound through `loadBalancerId`, `bindType` does not take effect (a load balancer does not need an association mode) and the value passed in is ignored.
* When a load balancer instance is bound through `loadBalancerId`, both single-IP (mask `/32`) and CIDR block EIPs are supported. A CIDR block EIP bound to a virtual network interface supports only `Passthrough` (visible mode), and CIDR block EIPs are not supported when binding to a NAT gateway or a high availability virtual IP.
* When a high availability virtual IP is bound through `haVipId`, `bindType` can only be `FullNat` (regular NAT mode). If another value is passed, all EIPs in this request fail to be bound.
* If the number of bindings exceeds the quota limit, you can contact Support to increase the quota.
* The interface returns the set of EIP IDs that failed to be bound. An empty set indicates that all of them were bound successfully.
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name | Required | Type                                                     | Description                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | -------- | -------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| eipIds         | Yes      | Array of String                                          | <p>ID of the EIP to be bound.</p><p>The EIP must be in the unbound status.</p><p>It can be obtained by calling <a href="/api-reference/zec/elastic-ip/describeeips.md">DescribeEips</a>.</p>                                                                                                                                                                                           |
| loadBalancerId | No       | String                                                   | <p>ID of the load balancer instance.</p><p>Only load balancers whose <code>ipStackType</code> is <code>IPv4</code> can be bound to elastic IPs. A load balancer supports only a single stack, and its <code>IPv6</code> public address is assigned through the <a href="/api-reference/zlb/load-balancer-instance/assignloadbalanceripv6.md">AssignLoadBalancerIpv6</a> interface.</p> |
| nicId          | No       | String                                                   | <p>ID of the virtual network interface.</p><p>It can be obtained by calling <a href="/api-reference/zec/vnic/describenetworkinterfaces.md">DescribeNetworkInterfaces</a>.</p>                                                                                                                                                                                                          |
| lanIp          | No       | String                                                   | <p>Private IP address on the network interface to be bound.</p><p>This field cannot be empty when the EIP is bound to a network interface.</p>                                                                                                                                                                                                                                         |
| natId          | No       | String                                                   | <p>ID of the NAT gateway.</p><p>It can be obtained by calling <a href="/api-reference/zec/nat-gateway/describenatgateways.md">DescribeNatGateways</a>.</p>                                                                                                                                                                                                                             |
| haVipId        | No       | String                                                   | <p>ID of the high availability virtual IP.</p><p>It can be obtained by calling <a href="/api-reference/zec/vpc-network/havip/describehavips.md">DescribeHaVips</a>.</p>                                                                                                                                                                                                                |
| bindType       | No       | [BindType](/api-reference/zec/datastructure.md#bindtype) | <p>Association mode.</p><p>It takes effect when the EIP is bound to a network interface.</p><p>Default value: FullNat</p>                                                                                                                                                                                                                                                              |

## 3. Output Parameters

| Parameter Name | Type            | Description                                                                                                           |
| -------------- | --------------- | --------------------------------------------------------------------------------------------------------------------- |
| requestId      | String          | <p>The unique request ID, which is returned for each request.</p><p>RequestId is required for locating a problem.</p> |
| failedEipIds   | Array of String | Elastic IP IDs that failed to bind.                                                                                   |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**1. Associate multiple elastic IPs (EIPs) with a specified network interface in the visible mode.**

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

Request：
{
  "nicId": "<nicId>",
  "lanIp": "10.0.0.2",
  "eipIds": ["<eipId1>","<eipId2>"],
  "bindType": "Passthrough"
}

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

**2. Associate multiple elastic IPs (EIPs) with a specified load balancer instance.**

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

Request：
{
  "loadBalancerId": "<loadBalancerId>",
  "eipIds": ["<eipId1>","<eipId2>"]
}

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

**3. Associate multiple elastic IPs (EIPs) with a specified NAT gateway.**

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

Request：
{
  "natId": "<natId>",
  "eipIds": ["<eipId1>","<eipId2>"]
}

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

**4. Associate an elastic IP (EIP) with a high availability virtual IP (HaVip).**

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

Request：
{
  "haVipId": "<haVipId>",
  "eipIds": ["<eipId1>"]
}

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

**5. Associate multiple elastic IPs (EIPs) with a high availability virtual IP (HaVip) at the same time.**

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

Request：
{
  "haVipId": "<haVipId>",
  "eipIds": ["<eipId1>", "<eipId2>"]
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "failedEipIds": []
  }
}
```

{% endtab %}
{% endtabs %}

## 5. Developer Resources

Zenlayer Cloud API 2.0 integrates [SDKs](/api-reference/api-introduction/toolkit/api-sdk.md)，to make it easier for you to call APIs. More programming languages will be supported.

## 6. Error Codes

The following only lists the error codes related to the API business logic. For other error codes, see [Common Error Codes](/api-reference/api-introduction/instruction/commonerrorcode.md).

| HTTP Status Code | Error Code                                        | Description                                               |
| ---------------- | ------------------------------------------------- | --------------------------------------------------------- |
| 400              | INVALID\_EIP\_BINDING\_MODE\_UNSUPPORTED          | EIP Block does not support NAT binding mode.              |
| 404              | INVALID\_LB\_NOT\_FOUND                           | Load balancer does not exist.                             |
| 400              | INVALID\_LB\_STATUS                               | State of load balancer is not supported.                  |
| 400              | INVALID\_REGION\_MISMATCH                         | The EIP is not in the same region as the target resource. |
| 404              | INVALID\_HAVIP\_NOT\_FOUND                        | The specified HaVip does not exist.                       |
| 400              | OPERATION\_DENIED\_EIP\_ASSIGNED\_LIMIT\_EXCEEDED | Elastic IP binding exceeds the allowed limit.             |
