> For the complete documentation index, see [llms.txt](https://docs.ionos.com/cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ionos.com/cloud/network-services/vpn-gateway/api-how-tos/create-wireguard-peer.md).

# Create Wireguard Peer

IONOS CLOUD VPN Gateway: create a WireGuard peer using the API

* Creates a new WireGuard Peer.
* The full WireGuard Peer needs to be provided to create the object. Optional data will be filled with defaults or left empty.

To create a WireGuard Peer, perform a `POST` request.

## Endpoint

Use a [<mark style="color:blue;">region-specific</mark>](/cloud/network-services/vpn-gateway/api-how-tos.md#endpoints) endpoint to create a WireGuard Peer: `https://vpn.{region}.ionos.com/wireguardgateways/{gatewayId}/peers`.

## Request

```bash
curl --location \
--request POST 'https://vpn.de-fra.ionos.com/wireguardgateways/85c79b4b-5b40-570a-b788-58dd46ea71e2/peers' \
--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="
  }
}'

```

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

| Body Parameters            | Required | Type    | Description                                                                                                                                                                   | Example                                                  |
| -------------------------- | -------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
| `metadata`                 | no       | object  | Metadata related to the WireGuard peer.                                                                                                                                       | `{}`                                                     |
| `properties`               | yes      | object  | Properties with all data needed to create a new WireGuard peer. Note: There is a limit of 20 peers per gateway.                                                               |                                                          |
| `properties.name`          | yes      | string  | The human-readable name of the WireGuard peer.                                                                                                                                | `My Company Gateway Peer`                                |
| `properties.description`   | no       | string  | Human-readable description of the WireGuard peer.                                                                                                                             | `Allows local machine A to connect to Datacenter LAN Y.` |
| `properties.endpoint`      | yes      | object  | Properties needed to define the WireGuard endpoint.                                                                                                                           |                                                          |
| `properties.endpoint.host` | yes      | string  | Hostname or IPV4 address that the WireGuard Server will connect to.                                                                                                           | `198.51.100.0/24`                                        |
| `properties.endpoint.port` | yes      | integer | Port that the WireGuard Server will connect to.                                                                                                                               | 51820                                                    |
| `properties.allowedIPs`    | yes      | array   | The subnet CIDRs that are allowed to connect to the WireGuard Gateway. Specify "a.b.c.d/xy" for an individual IP address. Specify "0.0.0.0/0" or "::/0" for all IP addresses. | `["198.51.100.0/24"]`                                    |
| `properties.publicKey`     | yes      | string  | The public key for the WireGuard peer.                                                                                                                                        | `no8iaSEoqfbI6PVYsdEiUU5efYdtKX8VAhKity19MWI=`           |
| {% endtab %}               |          |         |                                                                                                                                                                               |                                                          |

{% tab title="Path Parameters" %}
You can update the `gatewayId` value to get a specific WireGuard Gateway:

| Path Parameter | Type   | Description                             | Example                                |
| -------------- | ------ | --------------------------------------- | -------------------------------------- |
| `gatewayId`    | string | The ID (UUID) of the WireGuard Gateway. | `85c79b4b-5b40-570a-b788-58dd46ea71e2` |
| {% 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 to enable requests to authenticate using a JSON Web Token (JWT). |
| `Content-Type`    | yes      | string | Set this to `application/json`.                                                   |
| {% endtab %}      |          |        |                                                                                   |
| {% endtabs %}     |          |        |                                                                                   |

## Response

**201 Successful operation**

```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 created. the `id` and other details of the created WireGuard Peer are provided in the response.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.ionos.com/cloud/network-services/vpn-gateway/api-how-tos/create-wireguard-peer.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
