# Ensure Wireguard Peer

Ensures that the WireGuard Peer with the provided ID is created or modified. Remember to provide the full WireGuard Peer specification to ensure the WireGuard Peer 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 Peer with the provided ID is created or modified, perform `PUT` request.

{% hint style="info" %}
**Note:** If WireGuard Peer for a given `peerId` does not exist, a new one is created instead.
{% 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 Peer is created or modified: `https://vpn.{region}.ionos.com/wireguardgateways/{gatewayId}/peers/{peerId}`.

## Request

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

```bash
curl --location \
--request PUT 'https://vpn.de-fra.ionos.com/wireguardgateways/85c79b4b-5b40-570a-b788-58dd46ea71e2/peers/b62b3a40-adee-5b6c-b98d-be20bfcbdd91' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJraWQiO' \
--header 'Content-Type: application/json' \
--data-raw '{
  "metadata": {},
  "properties": {
    "name": "My Company Gateway Peer",
    "description": "Allows local machine A to connect to Datacenter LAN Y.",
    "endpoint": {
      "host": "198.51.100.0/24",
      "port": 51820
    },
    "allowedIPs": [
      "198.51.100.0/24"
    ],
    "publicKey": "no8iaSEoqfbI6PVYsdEiUU5efYdtKX8VAhKity19MWI="
  }
}'
```

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` |
| `peerId`        | string | The ID (UUID) of the WireGuard Peer.    | `b62b3a40-adee-5b6c-b98d-be20bfcbdd91` |

Below is the list of fields returned in the response for a WireGuard Peer:

| Response Parameters        | Type    | Description                                                            | Example                                                  |
| -------------------------- | ------- | ---------------------------------------------------------------------- | -------------------------------------------------------- |
| `id`                       | string  | The unique identifier (UUID) for the WireGuard Peer.                   | `b62b3a40-adee-5b6c-b98d-be20bfcbdd91`                   |
| `metadata`                 | object  | Metadata related to the WireGuard Peer.                                | `{}`                                                     |
| `properties`               | object  | Properties of the WireGuard Peer.                                      |                                                          |
| `properties.name`          | string  | The human-readable name of the WireGuard Peer.                         | `My Company Gateway Peer`                                |
| `properties.description`   | string  | Human-readable description of the WireGuard Peer.                      | `Allows local machine A to connect to Datacenter LAN Y.` |
| `properties.endpoint`      | object  | Endpoint details for the WireGuard Peer.                               |                                                          |
| `properties.endpoint.host` | string  | The host IP address or domain for the WireGuard Peer.                  | `198.51.100.0/24`                                        |
| `properties.endpoint.port` | integer | The port number for the WireGuard Peer.                                | `51820`                                                  |
| `properties.allowedIPs`    | array   | The subnet CIDRs that are allowed to connect to the WireGuard Gateway. | `["198.51.100.0/24"]`                                    |
| `properties.publicKey`     | string  | The public key for the WireGuard Peer.                                 | `no8iaSEoqfbI6PVYsdEiUU5efYdtKX8VAhKity19MWI=`           |

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`.                                                 |

## Response

**200 Successful operation**

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

```json
{
  "id": "b62b3a40-adee-5b6c-b98d-be20bfcbdd91",
  "type": "wireguardpeer",
  "href": "/wireguardgateways/{gatewayId}/peers/b62b3a40-adee-5b6c-b98d-be20bfcbdd91",
  "metadata": {
    "createdDate": "2020-12-10T13:37:50+01:00",
    "createdBy": "ionos:identity:::users/87f9a82e-b28d-49ed-9d04-fba2c0459cd3",
    "createdByUserId": "87f9a82e-b28d-49ed-9d04-fba2c0459cd3",
    "lastModifiedDate": "2020-12-11T13:37:50+01:00",
    "lastModifiedBy": "ionos:identity:::users/87f9a82e-b28d-49ed-9d04-fba2c0459cd3",
    "lastModifiedByUserId": "87f9a82e-b28d-49ed-9d04-fba2c0459cd3",
    "resourceURN": "ionos:<product>:<location>:<contract>:<resource-path>",
    "status": "AVAILABLE",
    "statusMessage": null
  },
  "properties": {
    "name": "My Company Gateway Peer",
    "description": "Allows local machine A to connect to Datacenter LAN Y.",
    "endpoint": {
      "host": "198.51.100.0/24",
      "port": 51820
    },
    "allowedIPs": [
      "198.51.100.0/24"
    ],
    "publicKey": "no8iaSEoqfbI6PVYsdEiUU5efYdtKX8VAhKity19MWI="
  }
}
```

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