# Update location in zone

Canonical page: https://docs.ovok.com/slim-apis/zones/update-location-in-zone

| Method | Path |
| --- | --- |
| `PUT` | `/v1/slim/zones/:zoneId/locations/:locationId` |

[Authentication](/authentication) · [Access policies](/access-policies)

Updates a location in a zone: its name, floor, room and bed, the devices assigned to it, and the resident on those devices.

**Auth:** Bearer token. The caller must be a practitioner, an admin, a super admin, or hold the "System Owner" access policy. The access policy must grant `Location:update` and `Device:update` (admins and super admins skip this check).
**Scope:** The zone must belong to the caller's project (from the token), its parent project, or one of its sub-projects. The location must be in the caller's project, and its managing organization must be the zone. Devices and residents named in the body must be in your project or a sub-project.

## Request [#request]

### Path parameters [#path-parameters]

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `zoneId` | `string (uuid)` | Yes | Zone (organization) id. |
| `locationId` | `string (uuid)` | Yes | Location id. |

### Body [#body]

The body is strict: a field that is not listed here fails validation.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | `string` | Yes | Location name. At least 1 character. Must be unique. |
| `floor` | `string` | No | Floor code. Omit to keep the current one. |
| `room` | `string` | No | Room code. Omit to keep the current one. |
| `bed` | `string` | No | Bed code. Omit to keep the current one. |
| `deviceId` | `string (uuid)` \| `string[]` \| `null` | No | The full set of devices at the location. `null` removes every device. Omit to keep them. |
| `patientId` | `string (uuid)` | No | Resident to place on the devices. Omit it to remove every resident from the devices. |

## Behaviour [#behaviour]

- `name` is required and must be unique among the locations your token can search, not counting this one.
- `floor`, `room` and `bed` replace only the values you send; omitted ones keep their stored value. The resulting floor, room and bed must not match another location in the zone.
- `deviceId` (one UUID or a list) sets the devices at the location to exactly that set: devices not listed are removed from it, new ones are added. `null` removes every device. Omit `deviceId` to leave the devices unchanged.
- `patientId` assigns that resident to the devices named in `deviceId`, or, without `deviceId`, to the location's single device. A resident assigned there before is unassigned from those devices.
- **Omitting `patientId` unassigns the current resident from every device at the location** (and from the devices in `deviceId`). Send the current `patientId` to keep the resident.
- A discharged resident cannot be assigned.
- The write is atomic and takes a short write lock on the devices and locations it touches.
- The response is the updated location, in the same shape as `GET /v1/slim/location/{id}`.

## Example [#example]

```bash
curl -X PUT 'https://api.sandbox.ovok.com/v1/slim/zones/1e6b8d30-2c4f-4a95-8d7e-b0a2c4e6f918/locations/5d2a9c64-7e1b-4830-b6f5-9a3c1e8d7b02' \
  -H "Authorization: Bearer ${OVOK_TOKEN}" \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "Room 101 Bed 1",
    "room": "101",
    "bed": "1",
    "deviceId": "8c5e7a21-4b9d-4f36-a1c8-0d2e6b9f3a54",
    "patientId": "3f1c2b7e-8d4a-4c1e-9b2f-6a7d5e4c3b21"
  }'
```

## Successful response [#successful-response]

`200` — Updated location.

```json
{
  "id": "5d2a9c64-7e1b-4830-b6f5-9a3c1e8d7b02",
  "name": "Room 101 Bed 1",
  "floor": "1",
  "room": "101",
  "bed": "1",
  "organizationId": "1e6b8d30-2c4f-4a95-8d7e-b0a2c4e6f918",
  "organizationName": "Zone A",
  "patientId": "3f1c2b7e-8d4a-4c1e-9b2f-6a7d5e4c3b21",
  "patientName": "demo-resident",
  "deviceId": ["8c5e7a21-4b9d-4f36-a1c8-0d2e6b9f3a54"],
  "deviceName": "Demo/1000001"
}
```

The body is the location after the update, as `GET /v1/slim/location/{id}` returns it.

| Field | Type | Description |
| --- | --- | --- |
| `id` | `string (uuid)` | Location id. |
| `name` | `string` | Location name. Empty string when the location has none. |
| `floor` | `string` | Floor code. Left out when not set. |
| `room` | `string` | Room code. Left out when not set. |
| `bed` | `string` | Bed code. Left out when not set. |
| `organizationId` | `string (uuid)` | Zone id. Left out when the location has no zone. |
| `organizationName` | `string` | Zone name. Left out when the location has no zone. |
| `deviceId` | `string[]` | Ids of every device at the location. Left out when there is none. |
| `deviceName` | `string` | Alphabetically first name among the devices at the location. Left out when there is none. |
| `patientId` | `string (uuid)` | Resident on the first device at the location that has one. Left out when there is none. |
| `patientName` | `string` | That resident's name. Left out when there is none. |

## Errors [#errors]

| Status | Meaning |
| --- | --- |
| [`401`](/errors/unauthenticated) | Bearer token is missing, invalid or expired. |
| [`403`](/errors/forbidden) | You are not a practitioner, admin or System Owner, you lack `Location:update` or `Device:update`, your session has no project, the zone is outside your project tree or carries no project, the location is not in this zone or not in your project, or a device or resident in the body is outside your project. |
| [`404`](/errors/not-found) | No zone with this `zoneId`, or no location with this `locationId`, exists. |
| [`409`](/errors/conflict) | A location with the same floor, room and bed already exists in this zone, or another write holds a lock on one of the devices or locations. Retry the call. |
| [`422`](/errors/validation-failed) | A path parameter is not a UUID, the body fails validation, a location with the same name already exists, a resident is discharged, or `patientId` is sent without `deviceId` while the location has no device or several. |
