# CreateNatGateway

## 1. API Description

This API (CreateNatGateway) is used to create a NAT gateway.

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

* <mark style="color:blue;">This API is an async API. A response is returned after the request is sent. You can call</mark> [<mark style="color:purple;">`DescribeNatGateways`</mark>](https://docs.console.zenlayer.com/api-reference/compute/zec/nat-gateway/describenatgateways) <mark style="color:blue;">to query the state of the NAT gateway. The</mark> <mark style="color:blue;">`RUNNING`</mark> <mark style="color:blue;">state means creating successfully.</mark>
* <mark style="color:blue;">Only pay-as-you-go NAT gateway creation is supported.</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 network ID to which the NAT gateway belongs.                                                                                |
| name            | Yes      | String                                                                                                 | <p>The name of the NAT gateway.</p><p>Length must be between 2 and 63 characters.</p><p>Available range: \[2.0, +).</p>         |
| subnetIds       | No       | Array of String                                                                                        | Subnet ID list to which the NAT gateway belongs.                                                                                |
| securityGroupId | No       | String                                                                                                 | <p>ID of the security group.</p><p>If not specified, the security group associated with global VPC will be used by default.</p> |
| resourceGroupId | No       | String                                                                                                 | <p>Resource Group ID</p><p>If not specified, it will belong to the default resource group.</p>                                  |
| tags            | No       | [TagAssociation](https://docs.console.zenlayer.com/api-reference/compute/datastructure#tagassociation) | <p>Bound tags when creating the NAT gateway.</p><p>Tag keys must be unique.</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.                                                                                                         |
| natGatewayId   | String | The unique ID of the NAT gateway.                                                                                     |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**Create a NAT gateway.**

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

Request：
{
    "regionId": "asia-east-1",
    "vpcId": "<vpcId>",
    "name": "name",
    "subnetIds": ["<subnet>", "<subnet>"],
    "resourceGroupId": "<resourceGroupId>"
}

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

{% 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\_REGION\_NOT\_FOUND                   | Specified availability zone does not exist.                     |
| 404              | INVALID\_VPC\_NOT\_FOUND                      | The global VPC does not exist.                                  |
| 404              | INVALID\_SUBNET\_NOT\_FOUND                   | Subnet does not exist.                                          |
| 400              | OPERATION\_DENIED\_NAT\_SUBNET\_CONFLICT      | Subnet is associated already.                                   |
| 400              | OPERATION\_DENIED\_SUBNET\_STATUS             | Subnet state is not supported.                                  |
| 400              | OPERATION\_DENIED\_SUBNET\_NAT\_CONFLICT      | Subnet is associated with a NAT gateway already.                |
| 404              | INVALID\_EIP\_NOT\_FOUND                      | Elastic IP does not exist.                                      |
| 400              | OPERATION\_DENIED\_EIP\_IS\_NOT\_UN\_ASSIGN   | Elastic IP is not in unassigned state.                          |
| 400              | OPERATION\_DENIED\_SNAT\_ENTRY\_COUNT\_LIMIT  | The number of SNAT entries is limited.                          |
| 400              | OPERATION\_DENIED\_DNAT\_ENTRY\_COUNT\_LIMIT  | The number of DNAT entries is limited.                          |
| 400              | OPERATION\_DENIED\_SUBNET\_TYPE\_NOT\_SUPPORT | Operations on subnets with such IP stack type is not supported. |
| 404              | INVALID\_SECURITY\_GROUP\_NOT\_FOUND          | The specified security group does not exist.                    |
