# 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>](/api-reference/compute/zec/vnic/describenetworkinterfaces.md) <mark style="color:blue;">to query supported vNIC.</mark>
* <mark style="color:blue;">You can call</mark> [<mark style="color:blue;">DescribeNatGateways</mark>](/api-reference/compute/zec/nat-gateway/describenatgateways.md) <mark style="color:blue;">to query supported NAT gateway.</mark>
* <mark style="color:blue;">You can call</mark> [<mark style="color:blue;">DescribeHaVips</mark>](https://github.com/zenlayer/zenlayercloud-api-doc-en/blob/main/zec/havip/describehavips.md) <mark style="color:blue;">to query supported high availability virtual IPs.</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;">,</mark> <mark style="color:blue;">`natId`</mark><mark style="color:blue;">, or</mark> <mark style="color:blue;">`haVipId`</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;">`haVipId`</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.                                                                                                                                |
| haVipId        | No       | String                                                           | The ID of the high availability virtual IP.                                                                                                    |
| bindType       | No       | [BindType](/api-reference/compute/zec/datastructure.md#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" %}
**1. 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"
  }
}
```

**2. Associate elastic IPs to 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 elastic IPs to 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 to 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 to 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                                   |
| ---------------- | ------------------------------------------------- | --------------------------------------------- |
| 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.                              |
| 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. |


---

# 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/compute/zec/elastic-ip/associateeipaddress.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.
