# RegisterBackend

## 1. API Description

This API (RegisterBackend) is used to add one or more backend servers to a load balance listener.

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

* <mark style="color:blue;">The state of the load balance instance must be</mark> <mark style="color:blue;">`RUNNING`</mark><mark style="color:blue;">.</mark>
* <mark style="color:blue;">Adding bare metal instances is supported. The bare metal instance must be connected to the border gateway of the load balancer’s VPC through the Layer 3 Cloud Router in Cloud Networking.</mark>
* <mark style="color:blue;">When adding a bare metal instance, only its private IP address should be specified; the instance ID must not be provided.</mark>
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name | Required | Type                                                                                                             | Description                                                                                                               |
| -------------- | -------- | ---------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| loadBalancerId | Yes      | String                                                                                                           | The ID of the load balance instance.                                                                                      |
| listenerId     | Yes      | String                                                                                                           | The listener ID of the load balancer.                                                                                     |
| backendServers | Yes      | Array of [BackendServer](https://docs.console.zenlayer.com/api-reference/networking/datastructure#backendserver) | <p>List of backend servers to be added.</p><p>The same server cannot be bound multiple times under a single listener.</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> |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**Add a backend server to a listener.**

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

Request：
{
  "loadBalancerId": "<loadBalancerId>",
  "listenerId": "<listenerId>",
  "backendServers": [
    {
      "instanceId": "<instanceId>",
      "privateIpAddress": "10.0.0.1",
      "weight": 100
    }
  ]
}

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                                                                                         |
| ---------------- | ------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| 409              | INVALID\_BACKEND\_INSTANCE\_LISTENER\_EXIST | Backend server already exists.                                                                      |
| 409              | INVALID\_BACKEND\_INSTANCE\_MULTIPLE        | Duplicated backend servers.                                                                         |
| 400              | INVALID\_BACKEND\_IP\_ADDRESS               | No instance found for the specified private IP of the backend server.                               |
| 409              | INVALID\_BACKEND\_IP\_ZBG\_REQUIRED         | A border gateway is required for the VPC to which the backend server IP belongs.                    |
| 400              | INVALID\_BACKEND\_SERVER\_IP\_INVALID       | Invalid backend server IP. The backend server IP must be a private IP.                              |
| 409              | INVALID\_BACKEND\_SERVER\_IP\_REPEAT        | Duplicated backend server IPs.                                                                      |
| 400              | INVALID\_BACKEND\_SERVER\_PORT              | In DR mode, full port, or listening on multiple ports, the backend server port cannot be specified. |
| 400              | INVALID\_INSTANCE\_IP\_ADDRESS              | The instance's private IP is invalid.                                                               |
| 404              | INVALID\_INSTANCE\_NOT\_FOUND               | Backend server does not exist.                                                                      |
| 404              | INVALID\_LB\_LISTENER\_NOT\_FOUND           | The listener does not exist.                                                                        |
| 400              | INVALID\_LB\_STATUS                         | Load balancer state is not supported.                                                               |
| 400              | INVALID\_RS\_QUOTA\_EXCEED\_PER\_LISTENER   | The number of backend servers under the listener exceeds the quota limit.                           |
