# API requests

The requests below are promised within `v1`. "A person" means signed in by an account, not a token. Each request's fields and refusal codes are in the full reference and in `qkvm/api_v1.json`.

## Sign-in and session

| Request | Who | Does |
|---|---|---|
| `GET /healthz` | nobody | running, `version`, `api` versions, `locked`, `video` |
| `GET /api/v1/session` | nobody | whether the wall is set up, and who is signed in |
| `POST /api/v1/login` | nobody | sign in with `password`, `name`, `code`, `remember` |
| `POST /api/v1/logout` | viewer, a person | sign out this session, the others, or all |
| `POST /api/v1/password` | viewer, a person | change one's own password |
| `POST /api/v1/totp/begin`, `enable`, `codes`, `disable` | viewer, a person | two-factor sign-in |
| `POST /api/v1/recover` | nobody | a new password with the recovery key |
| `POST /api/v1/display` | nobody | open a wall screen's link |
| `GET /api/v1/about` | viewer | version and licence |

## The wall and its machines

| Request | Who | Does |
|---|---|---|
| `GET /api/v1/wall` | viewer | the machines this account may see, with `can` and `target`; `interval`, `live` |
| `GET /api/v1/status` | viewer | how each machine is, by id |
| `GET /api/v1/devices/{id}/snapshot` | viewer | the screen as JPEG or PNG |
| `GET /api/v1/devices/{id}/history` | viewer | what the wall saw of the machine: [History](https://qkvm.com/docs/web/history) |
| `POST /api/v1/devices/{id}/live` | viewer | a one-use pass for the live line, then a WebSocket at the same path |
| `GET /api/v1/actions` | operator | saved actions, never their text |
| `GET /api/v1/devices/{id}/wol` | operator | what the KVM has saved to wake |
| `POST /api/v1/devices/{id}/actions` | operator | do something (below) |
| `PUT /api/v1/devices/{id}/view` | operator, a person | an Intel AMT PC's view: `health`, `stills` or `live` |
| `POST /api/v1/devices/{id}/console` | operator, a person | a one-use, signed-in way into a server's console |
| `.../media`, `media/unmount`, `media/upload`, `media/delete` | admin, a person | virtual media |

## Administration

| Request | Who | Does |
|---|---|---|
| `PUT /api/v1/wall/order` | admin | the tiles' order |
| `POST /api/v1/devices/remove` | admin | remove several machines, all or none |
| `GET`, `POST /api/v1/tokens`; `DELETE /api/v1/tokens/{id}` | admin | tokens and display links |
| `POST /api/v1/export`, `import/read`, `import` | admin, a person | export and import files |
| `GET /api/v1/audit?device=` | admin | the activity log of one machine |
| `GET /api/v1/devices/{id}/alert-picture/{stamp}` | admin | the picture a screen alert kept |
| `GET`, `PUT /api/v1/alerts`; `alerts/pause`; `alerts/test` | admin | the first destination, a pause, a test |

## Actions

`POST /api/v1/devices/{id}/actions` with `{"action": "..."}`. The last column is the word of `can` it needs.

| `action` | Does | Also give | Needs |
|---|---|---|---|
| `keys` | a key combination | `"keys": "MetaLeft,KeyL"`, up to eight | `keys` |
| `ctrl_alt_del` | that one | | `keys` |
| `text` | types text, up to 2000 characters | `"text"`, `"enter": true` | `text` |
| `custom` | a saved action | `"custom_id"`, `"custom_changed"` | `keys` or `text` |
| `atx_power`, `atx_power_long` | press or hold the power button | | `power` |
| `atx_reset` | press reset | | `reset` |
| `fingerbot_power`, `fingerbot_power_long` | a Fingerbot presses or holds power | | `fingerbot` |
| `power_on`, `power_off` | switch on, or ask to shut down | | `power_state` |
| `bios_setup` | start into the BIOS setup once | | `bios_setup` |
| `locate_on`, `locate_off` | a server's locator light | | `locator` |
| `reboot` | restart the KVM, or a server's controller | | `reboot` |
| `jiggler_on`, `jiggler_off` | keep awake, or allow sleep | | `jiggler` |
| `wol` | Wake-on-LAN from the KVM | `"mac"` | `wol` |
| `port` | show another input | `"port": 0` | `ports` |
| `resume` | take a JetKVM's picture back | | `resume` |

Add `"target"` with every action: see [The API](https://qkvm.com/docs/web/the-api).

```
curl -X POST -H "Authorization: Bearer qkvm_..." -H "Content-Type: application/json" -d '{"action": "ctrl_alt_del", "target": "<target from the wall>"}' https://qkvm.example:8787/api/v1/devices/<id>/actions
```

## Related

- [The API](https://qkvm.com/docs/web/the-api)
- [Clients and versions](https://qkvm.com/docs/web/clients-and-versions)
- [Scripts and wall screens](https://qkvm.com/docs/web/scripts-and-wall-screens)
- [History](https://qkvm.com/docs/web/history)

[Full reference](https://github.com/qkvm/qkvm/blob/main/GUIDE.md#the-requests)
