# CreateIpv4Block

## 1. API Description

This API is used to create one or more IPv4 CIDR blocks.

#### Prerequisites

* Query stock: call [`DescribeAvailableIpv4Resources`](https://docs.console.zenlayer.com/test/ci-develop-en/compute/bmc/cidrblock/describeavailableipv4resources) to check available resources.
* Cost estimation: know of CIDR block pricing. See [Billing Method](https://docs.console.zenlayer.com/welcome/pricing/bare-metal-cloud-pricing/billing-method#cidr-block) for more details.

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

* <mark style="color:blue;">If you create a subscription CIDR block, the amount required will be pre-deducted. If the balance is insufficient, the request will fail. If you create a pay-as-you-go CIDR block, please ensure your account balance is sufficient before calling this API.</mark>
* <mark style="color:blue;">Vouchers can be used for fee deduction in instance creation. See</mark> [<mark style="color:purple;">Vouchers</mark>](https://docs.console.zenlayer.com/welcome/platform/billing-center/vouchers) <mark style="color:blue;">for more details.</mark>
* <mark style="color:blue;">This API is an async API. A CIDR block ID list is returned after the creation request is sent. However, it does not mean the creation has been completed. The status of the CIDR block will be</mark> <mark style="color:blue;">`CREATING`</mark> <mark style="color:blue;">during the creation. You can use</mark> [<mark style="color:blue;">DescribeCidrBlocks</mark>](https://docs.console.zenlayer.com/test/ci-develop-en/compute/bmc/cidrblock/describecidrblocks) <mark style="color:blue;">to query the status of the CIDR block. If the status changes from</mark> <mark style="color:blue;">`Creating`</mark> <mark style="color:blue;">to</mark> <mark style="color:blue;">`Available`</mark><mark style="color:blue;">, it means that the CIDR block has been created successfully;</mark> <mark style="color:blue;">`CREATE_FAILED`</mark> <mark style="color:blue;">means the CIDR block has been created failed. Any operations on the instances are not allowed while creating.</mark>
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

<table><thead><tr><th width="161.79046630859375">Parameter Name</th><th width="109.2933349609375">Required</th><th width="99.19317626953125">Type</th><th>Description</th></tr></thead><tbody><tr><td>zoneId</td><td>Yes</td><td>String</td><td>Zone ID to which the CIDR blocks belong.</td></tr><tr><td>name</td><td>No</td><td>String</td><td><p>CIDR block name to be displayed.</p><p>This parameter can contain up to 64 characters.</p></td></tr><tr><td>chargeType</td><td>Yes</td><td>String</td><td><p>CIDR block <a href="https://docs.console.zenlayer.com/welcome/pricing/bare-metal-cloud-pricing/billing-method#cidr-block">pricing model</a>.</p><ul><li>PREPAID: subscription</li><li>POSTPAID: pay-as-you-go</li></ul></td></tr><tr><td>chargePrepaid</td><td>No</td><td><a href="../../datastructure#chargeprepaid">ChargePrepaid</a></td><td>Details of the monthly subscription, including the purchase period, auto-renewal. It is required if the <code>chargeType</code> is <code>PREPAID</code>.</td></tr><tr><td>netmask</td><td>Yes</td><td>Integer</td><td><p>Netmasks you want to purchase.</p><p>Value range: [1,32].</p><p>You can find the available netmasks in the response by calling <code>DescribeAvailableIpv4Resource</code>.</p></td></tr><tr><td>amount</td><td>No</td><td>Integer</td><td><p>Quantity of IPv4 CIDR blocks you want to purchase.</p><p>Default value: 1.</p></td></tr><tr><td>resourceGroupId</td><td>No</td><td>String</td><td><p>Resource group ID where the CIDR blocks reside.</p><p>If an available VLAN exists in the specified zone, this parameter will be ignored. The created CIDR blocks will be added to the resource group of the VLAN.</p></td></tr><tr><td>marketingOptions</td><td>No</td><td><a href="../../datastructure#marketingoptions">MarketingOptions</a></td><td>Information on marketing campaigns.</td></tr></tbody></table>

## 3. Output Parameters

<table><thead><tr><th width="161.73077392578125">Parameter Name</th><th width="137.82958984375">Type</th><th>Description</th></tr></thead><tbody><tr><td>requestId</td><td>String</td><td>The unique request ID, which is returned for each request. RequestId is required for locating a problem.</td></tr><tr><td>orderNumber</td><td>String</td><td>Number of order.</td></tr><tr><td>cidrBlockIds</td><td>Array of String</td><td>List of CIDR block IDs.</td></tr></tbody></table>

## 4. Code Example

{% tabs %}
{% tab title="Example 1" %}
Create a postpaid IPv4 CIDR block `example1` with the netmask of `29` \*\*\*\* in `IST-B`, belonging to `Default Resource Group`.

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

Request:
{
  "zoneId": "IST-B",
  "name": "example1",
  "chargeType": "POSTPAID",
  "netmask": 29
}

Response:
{
  "requestId": "T135376EE-7090-4773-B81E-7FB38358B656",
  "response": {
    "requestId": "T135376EE-7090-4773-B81E-7FB38358B656",
    "orderNumber": "orderNum",
    "cidrBlockIds": [
      "cidrBlockId"
    ]
  }
}
```

{% endtab %}

{% tab title="Example 2" %}
Create a prepaid IPv4 CIDR block `example2` with the netmask of `29` \*\*\*\* in `AMS-D`, belonging to `Default Resource Group`.

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

Request:
{
  "zoneId": "AMS-D",
  "name": "example2",
  "chargeType": "PREPAID",
  "chargePrepaid": {
    "period": 1
  },
  "netmask": 29,
  "amount": 1
}

Response:
{
  "requestId": "T3B843750-5B98-421B-9D74-D3234C664760",
  "response": {
    "requestId": "T3B843750-5B98-421B-9D74-D3234C664760",
    "orderNumber": "orderNum",
    "cidrBlockIds": [
      "cidrBlockId"
    ]
  }
}
```

{% endtab %}
{% endtabs %}

## 5. Developer Resources

Zenlayer Cloud API 2.0 integrates [SDKs](https://docs.console.zenlayer.com/test/ci-develop-en/api-introduction/software-toolkit/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/test/ci-develop-en/api-introduction/instruction/commonerrorcode).​

<table><thead><tr><th width="170.750732421875">HTTP Status Code</th><th>Error Code</th><th>Description</th></tr></thead><tbody><tr><td>404</td><td>INVALID_ZONE_NOT_FOUND</td><td>Zone not found.</td></tr><tr><td>403</td><td>OPERATION_DENIED_NETMASK_OUT_OF_STOCK</td><td>Netmask out of stock.</td></tr><tr><td>403</td><td>RESOURCE_INSUFFICIENT_PRODUCT_SOLD_OUT</td><td>Resources sold out.</td></tr></tbody></table>
