# CreateLoadBalancer

## 1. API Description

This API (CreateLoadBalancer) is used to create a load balancer instance.

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

* <mark style="color:blue;">You can call</mark> [<mark style="color:purple;">DescribeLoadBalancerRegions</mark>](https://docs.console.zenlayer.com/api-reference/networking/zlb/location/describeloadbalancerregions) <mark style="color:blue;">to check the available regions supporting the creating of load balancers.</mark>
* <mark style="color:blue;">This API is an async API. A response is returned after the request is sent. However, it does not mean the operation has been completed. You can call</mark> [<mark style="color:purple;">DescribeLoadBalancers</mark>](https://docs.console.zenlayer.com/api-reference/networking/zlb/load-balancer-instance/describeloadbalancers) <mark style="color:blue;">to query the state of the load balancer instance. The</mark> <mark style="color:blue;">`RUNNING`</mark> <mark style="color:blue;">state means creating successfully.</mark>
* <mark style="color:blue;">Currently only creating load balance instances for Elastic Compute is supported.</mark>
* <mark style="color:blue;">Only pay-as-you-go load balance instance creation is supported.</mark>
* <mark style="color:blue;">Please ensure that the global VPC contains an</mark> <mark style="color:blue;">**IPv4 subnet**</mark><mark style="color:blue;">, and that the subnet has</mark> <mark style="color:blue;">**at least two available IP addresses**</mark> <mark style="color:blue;">for allocation.</mark>
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name              | Required | Type                                                                                                              | Description                                                                                                                                                                                                                                                    |
| --------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| regionId                    | Yes      | String                                                                                                            | Region ID.                                                                                                                                                                                                                                                     |
| vpcId                       | Yes      | String                                                                                                            | VPC ID to which the load balance backend server belongs.                                                                                                                                                                                                       |
| loadBalancerName            | Yes      | String                                                                                                            | <p>Load balance instance name.</p><p>Containing 1 to 64 characters.</p><p>Available range: \[1.0, +).</p><p>Value range: \[1.0, +)</p>                                                                                                                         |
| internetChargeType          | No       | [InternetChargeType](https://docs.console.zenlayer.com/api-reference/networking/datastructure#internetchargetype) | IP network billing model.                                                                                                                                                                                                                                      |
| ipNetworkType \[Deprecated] | No       | [EipNetworkType](https://docs.console.zenlayer.com/api-reference/networking/datastructure#eipnetworktype)         | <p>IP network type.</p><p>Deprecated. Please use networkLineType instead.</p>                                                                                                                                                                                  |
| networkLineType             | No       | [NetworkLineType](https://docs.console.zenlayer.com/api-reference/networking/datastructure#networklinetype)       | IP network type.                                                                                                                                                                                                                                               |
| bandwidthMbps               | No       | Integer                                                                                                           | <p>Maximum outbound bandwidth of the elastic IP.</p><p>Unit: Mbps.</p><p>The maximum limit is usually 10000 Mbps. If you have additional requirements, please contact Support.</p><p>Available range: \[1, +).</p><p>Value range: \[1, +)</p>                  |
| trafficPackageSize          | No       | Float                                                                                                             | <p>Data transfer package size.</p><p>The parameter is only required when internetChargeType is ByTrafficPackage.</p><p>Available range: \[0.0, 999999.0].</p><p>Value range: \[0.0, 999999.0]</p>                                                              |
| bandwidthClusterId          | No       | String                                                                                                            | <p>ID of bandwidth cluster.</p><p>The parameter is only required when internetChargeType is BandwidthCluster.</p>                                                                                                                                              |
| resourceGroupId             | No       | String                                                                                                            | <p>Resource Group ID</p><p>If not specified, the load balance instance will belong to the default resource group.</p>                                                                                                                                          |
| number                      | No       | Integer                                                                                                           | <p>The number of created load balancers.</p><p>Default value: 1</p>                                                                                                                                                                                            |
| marketingOptions            | No       | [MarketingInfo](https://docs.console.zenlayer.com/api-reference/networking/datastructure#marketinginfo)           | Information on marketing campaigns.                                                                                                                                                                                                                            |
| tags                        | No       | [TagAssociation](https://docs.console.zenlayer.com/api-reference/networking/datastructure#tagassociation)         | <p>Bound tags when creating the load balancer.</p><p>Tag keys must be unique.</p>                                                                                                                                                                              |
| subnetId                    | No       | String                                                                                                            | <p>ID of the subnet where the health check private source IP belong.</p><p>You can call DescribeSubnets to obtain details.</p>                                                                                                                                 |
| healthCheckPrivateIps       | No       | Array of String                                                                                                   | <p>Health probe private IP.</p><p>When subnetId is specified, this parameter is required with a quantity of 2.</p><p>If subnetId is not specified, this parameter is invalid. When this value is left empty, IP addresses will be allocated automatically.</p> |
| securityGroupId             | No       | String                                                                                                            | <p>Security group ID.</p><p>You can call DescribeSecurityGroups to obtain details.</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> |
| orderNumber     | String          | Order number.                                                                                                         |
| loadBalancerIds | Array of String | A collection of unique IDs of the load balancers.                                                                     |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**Create a public network load balancer. IP billing method is flat rate.**

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

Request：
{
  "regionId" : "asia-east-1",
  "vpcId" : "<vpcId>",
  "securityGroupId" : "<securityGroupId>",
  "loadBalancerName" : "sample",
  "internetChargeType" : "ByBandwidth",
  "ipNetworkType" : "BGPLine",
  "bandwidthMbps" : 2,
  "trafficPackageSize" : null,
  "bandwidthClusterId" : "",
  "number" : 1
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "orderNumber": "<orderNumber>",
    "loadBalancerIds": ["<loadBalancerId>"]
  }
}
```

{% 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                                                    |
| ---------------- | --------------------------------------------------- | -------------------------------------------------------------- |
| 400              | INVALID\_IP\_BROADCAST\_ADDRESS                     | Invalid IP address: broadcast addresses are not allowed.       |
| 400              | INVALID\_IP\_FIRST\_ADDRESS                         | Invalid IP address: gateway addresses are not allowed.         |
| 400              | INVALID\_IP\_NETWORK\_ADDRESS                       | Invalid IP address: network addresses are not allowed.         |
| 400              | INVALID\_IP\_OUT\_OF\_RANGE                         | Invalid IP address: not within the CIDR range.                 |
| 404              | INVALID\_REGION\_NOT\_FOUND                         | Specified region does not exist.                               |
| 404              | INVALID\_SECURITY\_GROUP\_NOT\_FOUND                | Security group does not exist.                                 |
| 400              | INVALID\_SUBNET\_NOT\_BELONG\_TO\_VPC               | Specified subnet is not within the global VPC.                 |
| 404              | INVALID\_SUBNET\_NOT\_FOUND                         | Subnet does not exist.                                         |
| 409              | INVALID\_SUBNET\_PRIVATE\_IPV4\_IN\_USED            | Preset private IP is already be used.                          |
| 404              | INVALID\_VPC\_NOT\_FOUND                            | Global VPC does not exist.                                     |
| 400              | OPERATION\_DENIED\_EIP\_INSUFFICIENT                | Insufficient elastic IP addresses. Operation failed.           |
| 400              | OPERATION\_DENIED\_EIP\_QUOTA\_LIMIT\_EXCEEDED      | The number of elastic IP addresses exceeds limit.              |
| 400              | OPERATION\_DENIED\_SUBNET\_TYPE\_NOT\_SUPPORT       | Subnet stack type is not supported.                            |
| 400              | OPERATION\_DENIED\_SUBNET\_TYPE\_NOT\_SUPPORT\_IPV4 | IPv4 subnet stack type is not supported.                       |
| 409              | OPERATION\_DENIED\_NO\_AVAILABLE\_SUBNET            | No valid subnet exists under the global VPC. Operation failed. |
