# Update a VM

> Change the sleep policy of a VM, its wakes and its backups. A field that you do not send keeps its value.

`PATCH /v1/tenants/{tenant}/vms/{name}`

```bash curl
curl -X PATCH "https://api.shako.dev/v1/tenants/acme/vms/web1" \
  -H "Authorization: Bearer $SHAKO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"sleep":"never"}'
```

```python Python
import os

import requests

response = requests.patch(
    "https://api.shako.dev/v1/tenants/acme/vms/web1",
    headers={"Authorization": f"Bearer {os.environ['SHAKO_API_KEY']}"},
    json={
        "sleep": "never",
    },
)
response.raise_for_status()
print(response.json())
```

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

```json 200 (excerpt)
{
  "name": "web1",
  "tenant": "acme",
  "state": "awake",
  "ssh": "web1.acme.shako.dev",
  "vcpus": 1,
  "mem_mib": 2048,
  "disk_gb": 10
}
```

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.

**name** `string` *required*

The VM's name.

## Request body

**sleep** `string (auto, never)` (default: no change)

When the VM sleeps. auto: when it is quiet. never: it stays on, and it restarts after a reboot or a crash. With both, the sleep and wake endpoints work at once.

**idle** `string` (default: no change)

The quiet time before the VM sleeps, for example "15m" or "2h".

**wake_on_cron** `boolean` (default: no change)

true: after each sleep, the VM wakes 2 minutes before its next cron job.

**wake_on_chat** `boolean` (default: no change)

true: a chat message wakes the VM.

**backup** `boolean` (default: no change)

true: each night, Shako backs up the VM if its disk changed. false: no new backups, and the old backups go 7 days after they were taken.

**after_delete** `string (keep-7d, erase)` (default: no change)

What happens to the VM's backups when the VM is deleted. keep-7d: they stay 7 days, then Shako erases them. erase: Shako erases them within a few minutes.

## Response

200 with [the VM object](https://shako.dev/api/objects/vm-view.md).

The errors: https://shako.dev/api/errors.md. All the endpoints of VMs: https://shako.dev/api/vms.md.
