# Create device

Canonical page: https://docs.ovok.com/api/slim/device/create-device

`POST /v1/slim/device`

Creates a device in your project and, optionally, assigns it to a zone, a location and a resident in the same write.

**Auth:** bearer token. The caller must be a practitioner, an admin or a System Owner, and needs `Device:create`.
**Scope:** the device is created in the caller's project (from the token).

## Behaviour

- `name` is stored, trimmed, as the device's user-friendly name and as its official device identifier.
- A `name` whose serial a device of your project already holds is refused with 422, in any spelling: spaces around it or its `/`, other case, with or without the manufacturer prefix ingest gives the serial (`Sleepiz/30QD24001`, `sleepiz/30qd24001` and `30QD24001` hold one serial). Ingest finds a device by its serial, so one serial belongs to one device.
- A `name` whose serial a device of another customer already holds is refused with 409, in the same spellings. Ingest routes readings by serial, and cannot tell two customers' devices with one serial apart.
- `thingsboardId` is stored as a second identifier. When you omit it, Ovok generates a random UUID for it.
- `organizationId`, `locationId` and `patientId` are optional. Each one you send is assigned in the same transaction as the create. If any part fails, nothing is written.
- A device in a room is in the room's zone. An `organizationId` that differs from the zone of the device's room (the room you send, or the one it is in) answers 422 with `path: ["organizationId"]` and changes nothing: move the room to that zone, or the device to a room in it. A device with no room, or in a room with no zone, takes any zone. A zone change re-zones only the device, never its room, the room's other devices or a resident.
- Assigning a resident moves them: the resident is removed from every other device they hold, and their active out-of-bed episode is closed.
- Assigning a resident who is not active (`discharged`, `discharged-recent` or `archived`) is refused with 422 and nothing is created: reactivate them first.
- The device starts with status `active`.
- The create is recorded in the change history.
- The response is the same as `GET /v1/slim/device/{id}` for the new device.

## Example

```bash
curl -X POST 'https://api.sandbox.ovok.com/v1/slim/device' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NjcyNjg4MDAsImV4cCI6MTc2NzI3MjQwMH0.Ql3B_ztDvctlyZ2z0vp4sl3ExXRQGkzmxdmTAqxNzZk' \
  -H 'Content-Type: application/json' \
  -d '{"name": "Sleepiz/3001000", "locationId": "c3499c27-2973-0a7f-807e-fb8676a92dcb"}'
```
