# AssociateEipAddress

## 1. API Description

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

{% hint style="info" %} <mark style="color:blue;">**Note**</mark>

* <mark style="color:blue;">You can call</mark> [<mark style="color:blue;">DescribeLoadBalancers</mark>](https://github.com/zenlayer/zenlayercloud-api-doc-en/blob/main/networking/zlb/load-balancer-instance/describeloadbalancers.md) <mark style="color:blue;">to query supported load balancers.</mark>
* <mark style="color:blue;">You can call</mark> [<mark style="color:blue;">DescribeNetworkInterfaces</mark>](https://docs.console.zenlayer.com/api-reference/compute/zec/vnic/describenetworkinterfaces) <mark style="color:blue;">to query supported vNIC.</mark>
* <mark style="color:blue;">You can call</mark> [<mark style="color:blue;">DescribeNatGateways</mark>](https://docs.console.zenlayer.com/api-reference/compute/zec/nat-gateway/describenatgateways) <mark style="color:blue;">to query supported NAT gateway.</mark>
* <mark style="color:blue;">You must specify exactly one of the following parameters:</mark> <mark style="color:blue;">`loadBalancerId`</mark><mark style="color:blue;">,</mark> <mark style="color:blue;">`nicId`</mark><mark style="color:blue;">, or</mark> <mark style="color:blue;">`natId`</mark><mark style="color:blue;">, in order of priority:</mark> <mark style="color:blue;">`loadBalancerId`</mark> <mark style="color:blue;">></mark> <mark style="color:blue;">`nicId`</mark> <mark style="color:blue;">></mark> <mark style="color:blue;">`natId`</mark><mark style="color:blue;">.</mark>
* <mark style="color:blue;">If the upper limit is exceeded, please contact us to request a quota increase.</mark>
* <mark style="color:blue;">The API returns the elastic IP IDs that failed to operate. An empty list indicates all operations succeeded.</mark>
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name | Required | Type                                                                                       | Description                                                                                                                                    |
| -------------- | -------- | ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| eipIds         | Yes      | Array of String                                                                            | ID list of elastic IPs.                                                                                                                        |
| loadBalancerId | No       | String                                                                                     | Load balancer ID.                                                                                                                              |
| nicId          | No       | String                                                                                     | vNIC ID.                                                                                                                                       |
| lanIp          | No       | String                                                                                     | <p>Private IP.</p><p>If nicId is provided, this field is required.</p>                                                                         |
| natId          | No       | String                                                                                     | NAT gateway ID.                                                                                                                                |
| bindType       | No       | [BindType](https://docs.console.zenlayer.com/api-reference/compute/datastructure#bindtype) | <p>Elastic IP mode.</p><p>Default value: FullNat .</p><p>Effective when the elastic IP is assigned to a vNIC.</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" %}
**Associate elastic IPs to a specified vNIC with the Cut-through 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"
  }
}
```

{% endtab %}
{% endtabs %}

## 5. Developer Resources

Zenlayer Cloud API 2.0 integrates [SDKs](https://docs.console.zenlayer.com/api-reference/api-introduction/toolkit/api-sdk)，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](https://docs.console.zenlayer.com/api-reference/api-introduction/instruction/commonerrorcode).

| HTTP Status Code | Error Code                                        | Description                                   |
| ---------------- | ------------------------------------------------- | --------------------------------------------- |
| 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                         | Region mismatch.                              |
| 400              | OPERATION\_DENIED\_EIP\_ASSIGNED\_LIMIT\_EXCEEDED | Elastic IP binding exceeds the allowed limit. |
