# Ensure Wireguard Gateway

Ensures that the WireGuard Gateway with the provided ID is created or modified. Remember to provide the full WireGuard Gateway specification to ensure the WireGuard Gateway with the respective ID is created or updated. When left empty, they are filled with default values or remain empty; previously provided values are not used for these empty fields.

To ensure that the WireGuard Gateway with the provided ID is created or modified, perform `PUT` request.

{% hint style="info" %}
**Note:**

* If WireGuard Gateway for a given `gatewayId` does not exist, a new one is created instead.
* VPN Gateways do not support connecting to LANs directly managed by Managed Kubernetes. However, you can attach additional LANs to node pools and connect these LANs to a VPN Gateway.
  {% endhint %}

## Endpoint

Use a [<mark style="color:blue;">region-specific</mark>](https://docs.ionos.com/sections-test/guides/network-services/vpn-gateway/api-how-tos/..#endpoints) endpoint to ensure that the WireGuard Gateway is created or modified: `https://vpn.{region}.ionos.com/wireguardgateways/{gatewayId}`.

## Request

{% hint style="info" %}
**Note:** The following request contains a sample `gatewayId`. Replace them with the `gatewayId` value whose information you want to update.
{% endhint %}

```bash
curl --location \
--request PUT 'https://vpn.de-fra.ionos.com/wireguardgateways/85c79b4b-5b40-570a-b788-58dd46ea71e2' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJraWQiO' \
--header 'Content-Type: application/json' \
--data-raw '{
  "id": "85c79b4b-5b40-570a-b788-58dd46ea71e2",
  "metadata": {},
  "properties": {
    "name": "My Company Gateway",
    "description": "This gateway allows connections to Datacenter LAN X.",
    "gatewayIP": "192.0.2.0",
    "interfaceIPv4CIDR": "172.17.0.1/32",
    "interfaceIPv6CIDR": "2001:0db8:85a3::/128",
    "connections": [
      {
        "datacenterId": "5a029f4a-72e5-11ec-90d6-0242ac120003",
        "lanId": "2",
        "ipv4CIDR": "192.168.1.100/24",
        "ipv6CIDR": "2001:0db8:85a3::/24"
      }
    ],
    "privateKey": "0HpE4BNwGHabeaC4aY/GFxB6fBSc0d49Db0qAzRVSVc=",
    "listenPort": 51820
  }
}'
```

{% tabs %}
{% tab title="Path Parameters" %}
Below is the list of mandatory path parameters:

| Path Parameters | Type   | Description                             | Example                                |
| --------------- | ------ | --------------------------------------- | -------------------------------------- |
| `gatewayId`     | string | The ID (UUID) of the WireGuard Gateway. | `85c79b4b-5b40-570a-b788-58dd46ea71e2` |
| {% endtab %}    |        |                                         |                                        |

{% tab title="Request Body Parameters" %}
Below is the list of mandatory body parameters for updating a WireGuard Gateway:

| Body Parameters                | Required | Type    | Description                                                                  | Example                                                                                                                                           |
| ------------------------------ | -------- | ------- | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`                           | yes      | string  | The ID (UUID) of the WireGuard Gateway to update.                            | `85c79b4b-5b40-570a-b788-58dd46ea71e2`                                                                                                            |
| `metadata`                     | no       | object  | Metadata                                                                     | `{}`                                                                                                                                              |
| `properties`                   | yes      | object  | Properties with all data needed to update the WireGuard Gateway.             |                                                                                                                                                   |
| `properties.name`              | yes      | string  | The human readable name of your WireGuard Gateway.                           | `My Company Gateway`                                                                                                                              |
| `properties.description`       | no       | string  | Human readable description of the WireGuard Gateway.                         | `This gateway allows connections to Datacenter LAN X.`                                                                                            |
| `properties.gatewayIP`         | yes      | string  | Public IP address to be assigned to the gateway.                             | `192.0.2.0`                                                                                                                                       |
| `properties.interfaceIPv4CIDR` | no       | string  | The IPV4 address (with CIDR mask) to be assigned to the WireGuard interface. | `172.16.0.1/32`                                                                                                                                   |
| `properties.interfaceIPv6CIDR` | no       | string  | The IPV6 address (with CIDR mask) to be assigned to the WireGuard interface. | `2001:0db8:85a3::/128`                                                                                                                            |
| `properties.connections`       | yes      | array   | The network connection for your gateway.                                     | `[ { "datacenterId": "5a029f4a-72e5-11ec-90d6-0242ac120003", "lanId": "2", "ipv4CIDR": "192.168.1.100/24", "ipv6CIDR": "2001:0db8:85a3::/24" } ]` |
| `properties.privateKey`        | yes      | string  | PrivateKey used for WireGuard Server.                                        | `0HpE4BNwGHabeaC4aY/GFxB6fBSc0d49Db0qAzRVSVc=`                                                                                                    |
| `properties.listenPort`        | no       | integer | Port that WireGuard Server will listen on.                                   | 51820                                                                                                                                             |
| {% endtab %}                   |          |         |                                                                              |                                                                                                                                                   |

{% tab title="Request Header Parameters" %}
To make authenticated requests to the API, the following fields are mandatory in the request header:

| Header Parameters | Required | Type   | Description                                                                     |
| ----------------- | -------- | ------ | ------------------------------------------------------------------------------- |
| `Authorization`   | yes      | string | The Bearer token enables requests to authenticate using a JSON Web Token (JWT). |
| `Content-Type`    | yes      | string | Set this to `application/json`.                                                 |
| {% endtab %}      |          |        |                                                                                 |
| {% endtabs %}     |          |        |                                                                                 |

## Response

**200 Successful operation**

Following is an example of when a WireGuard Gateway is successfully created.

```json
{
  "id": "85c79b4b-5b40-570a-b788-58dd46ea71e2",
  "metadata": {},
  "properties": {
    "name": "My Company Gateway",
    "description": "This gateway allows connections to Datacenter LAN X.",
    "gatewayIP": "81.173.1.2",
    "interfaceIPv4CIDR": "172.16.0.1/30",
    "interfaceIPv6CIDR": "fd00::2/128",
    "connections": [
      {
        "datacenterId": "5a029f4a-72e5-11ec-90d6-0242ac120003",
        "lanId": "2",
        "ipv4CIDR": "192.168.1.100/24",
        "ipv6CIDR": "fd28:5f8d:d9fe:08bd::/64"
      }
    ],
    "privateKey": "0HpE4BNwGHabeaC4aY/GFxB6fBSc0d49Db0qAzRVSVc=",
    "listenPort": 51820,
    "tier": "STANDARD",
    "maintenanceWindow": {
      "time": "16:30:59",
      "dayOfTheWeek": "Monday"
    }
  }
}
```

{% hint style="success" %}
**Result:** The WireGuard Gateway is successfully updated or created.
{% endhint %}
