# Add a device

> Add a device to the private network of the tenant.

`POST /v1/tenants/{tenant}/devices`

```bash curl
curl -X POST "https://api.shako.dev/v1/tenants/acme/devices" \
  -H "Authorization: Bearer $SHAKO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"laptop","public_key":"mH4V0sQ7..."}'
```

```python Python
import os

import requests

response = requests.post(
    "https://api.shako.dev/v1/tenants/acme/devices",
    headers={"Authorization": f"Bearer {os.environ['SHAKO_API_KEY']}"},
    json={
        "name": "laptop",
        "public_key": "mH4V0sQ7...",
    },
)
response.raise_for_status()
print(response.json())
```

```javascript JavaScript
const response = await fetch("https://api.shako.dev/v1/tenants/acme/devices", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.SHAKO_API_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({
    "name": "laptop",
    "public_key": "mH4V0sQ7..."
  }),
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
```

```json 201 (excerpt)
{
  "name": "laptop",
  "address": "100.96.0.2",
  "gateway": "100.96.0.1",
  "endpoint": "wg.shako.dev:51820",
  "public_key": "Bq9z..."
}
```

Authenticate with `Authorization: Bearer <API key>` on `https://api.shako.dev`. Role: contributor or owner.

## Path parameters

**tenant** `string` *required*

The tenant's name, from GET /v1/tenants.

## Request body

**name** `string` *required*

The device's name. It is unique in the tenant.

**public_key** `string` *required*

The device's WireGuard public key, in base64. The private key stays on the device.

## Response

201 with [the added device object](https://shako.dev/api/objects/device-added.md).

## Behavior

The answer has what the device's WireGuard config needs. The private key never leaves the device.

The errors: https://shako.dev/api/errors.md. All the endpoints of Devices: https://shako.dev/api/devices.md.
