# Update a NAT Gateway Rule

Modify a NAT gateway rule by performing a `PUT` (full replacement) or `PATCH` (partial update) request.

## Endpoint

`https://api.ionos.com/cloudapi/v6/datacenters/{datacenterId}/natgateways/{natGatewayId}/rules/{ruleId}`

## Request

### Full update (PUT)

```bash
curl --location \
--request PUT 'https://api.ionos.com/cloudapi/v6/datacenters/15f67991-0f51-4efc-a8ad-ef1fb31a480c/natgateways/8b3a6e2d-c9f1-4d3e-a7b2-1e4f8c9d3a2b/rules/5d4c3b2a-1e9f-8d7c-6b5a-4f3e2d1c0b9a' \
--header 'Authorization: Bearer $IONOS_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
  "properties": {
    "name": "Updated NAT Rule",
    "type": "SNAT",
    "protocol": "TCP",
    "sourceSubnet": "10.0.1.0/24",
    "publicIp": "203.0.113.15",
    "targetSubnet": "10.0.2.0/24",
    "targetPortRange": {
      "start": 8080,
      "end": 8090
    }
  }
}'
```

### Partial update (PATCH)

```bash
curl --location \
--request PATCH 'https://api.ionos.com/cloudapi/v6/datacenters/15f67991-0f51-4efc-a8ad-ef1fb31a480c/natgateways/8b3a6e2d-c9f1-4d3e-a7b2-1e4f8c9d3a2b/rules/5d4c3b2a-1e9f-8d7c-6b5a-4f3e2d1c0b9a' \
--header 'Authorization: Bearer $IONOS_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
  "properties": {
    "name": "Modified NAT Rule",
    "targetPortRange": {
      "start": 9000,
      "end": 9100
    }
  }
}'
```

{% tabs %}
{% tab title="Request Body Parameters" %}
The following table lists the request body parameters:

| **Body Parameters**                | **Required** | **Type** | **Description**                                              | **Example**        |
| ---------------------------------- | ------------ | -------- | ------------------------------------------------------------ | ------------------ |
| `properties.name`                  | No           | string   | Specifies a human-readable name for the NAT rule.            | `Updated NAT Rule` |
| `properties.type`                  | No           | string   | Defines the NAT rule type.                                   | `SNAT`             |
| `properties.protocol`              | No           | string   | Sets the network protocol. Defaults to `ALL`.                | `TCP`              |
| `properties.sourceSubnet`          | No           | string   | Specifies the source subnet in CIDR notation.                | `10.0.1.0/24`      |
| `properties.publicIp`              | No           | string   | Defines the public IP address for the NAT rule.              | `203.0.113.15`     |
| `properties.targetSubnet`          | No           | string   | Specifies the target or destination subnet in CIDR notation. | `10.0.2.0/24`      |
| `properties.targetPortRange`       | No           | object   | Defines the target port range of the NAT rule.               |                    |
| `properties.targetPortRange.start` | No           | integer  | Sets the inclusive start of the target port range.           | `8080`             |
| `properties.targetPortRange.end`   | No           | integer  | Sets the inclusive end of the target port range.             | `8090`             |
| {% endtab %}                       |              |          |                                                              |                    |

{% tab title="Request Header Parameters" %}
Include the following mandatory fields in the request header to authenticate your requests:

| **Header Parameters** | **Required** | **Type** | **Description**                                                             |
| --------------------- | ------------ | -------- | --------------------------------------------------------------------------- |
| `Authorization`       | Yes          | string   | Use a Bearer token to authenticate requests through a JSON Web Token (JWT). |
| `Content-Type`        | Yes          | string   | Set it to `application/json`.                                               |
| {% endtab %}          |              |          |                                                                             |
| {% endtabs %}         |              |          |                                                                             |

## Response

A **202 Accepted** response indicates that the NAT Gateway rule is successfully updated. The resource maintains a `BUSY` status until the update completes. The `id` and updated properties are provided in the response.

{% hint style="info" %}
**Note:** NAT Gateway rule updates are performed asynchronously. The response includes a `Location` header with a URL to poll the request status.
{% endhint %}

```json
{
  "id": "5d4c3b2a-1e9f-8d7c-6b5a-4f3e2d1c0b9a",
  "type": "nat-gateway-rule",
  "href": "/datacenters/15f67991-0f51-4efc-a8ad-ef1fb31a480c/natgateways/8b3a6e2d-c9f1-4d3e-a7b2-1e4f8c9d3a2b/rules/5d4c3b2a-1e9f-8d7c-6b5a-4f3e2d1c0b9a",
  "metadata": {
    "createdDate": "2024-01-15T09:30:00+00:00",
    "createdBy": "ionos:identity:::users/87f9a82e-b28d-49ed-9d04-fba2c0459cd3",
    "createdByUserId": "87f9a82e-b28d-49ed-9d04-fba2c0459cd3",
    "lastModifiedDate": "2024-01-15T10:45:00+00:00",
    "lastModifiedBy": "ionos:identity:::users/87f9a82e-b28d-49ed-9d04-fba2c0459cd3",
    "lastModifiedByUserId": "87f9a82e-b28d-49ed-9d04-fba2c0459cd3",
    "status": "BUSY"
  },
  "properties": {
    "name": "Updated NAT Rule",
    "type": "SNAT",
    "protocol": "TCP",
    "sourceSubnet": "10.0.1.0/24",
    "publicIp": "203.0.113.15",
    "targetSubnet": "10.0.2.0/24",
    "targetPortRange": {
      "start": 8080,
      "end": 8090
    }
  }
}
```


---

# 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.ionos.com/cloud/network-services/nat-gateway/api-howtos/update-nat-gateway-rule.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.
