# Device records

> One record for each enrolled device, with its standing, its operating system, and whether it's connected now.

Every enrolled device has a record in your realm. It's the list you check to see which devices you have, which of
them are online right now, and which have been revoked. It also notes the users who approved each device for AI
governance, and the AI agents you've recorded as running there.

## Before you begin

- **Privilege:** listing and reading need `READ` on the realm's endpoint settings, which `RealmViewer` and
  `RealmOwner` hold; recording an agent on a device needs `MODIFY`, which `RealmOwner` holds
  ([Who can call](../../api/#who-can-call)).
- **Where:** the API.

## How it works

The record is made at [Device enrollment](../../enrollment/device-enrollment/) and goes at
[Device removal](../../revoke-and-remove/removal/). The users who approve a device for AI governance are added to
its record as they do (see [AI governance sign-in](../../../ai-governance/fleet/user-sign-in/)). A user stays in `users`
once added: dropping the device from the AI fleet, or another user's approval, doesn't take them off.

A device is known by two ids, and you'll meet both:

- **The device id** is the record's `id`. Every call on this page about one device takes it.
- **The sensor id** is `dar.agentId` on the record. The security log and response calls take it, under the name the
  API gives sensors, `agent` (`agent=<sensor id>`, `"agents": [...]`). See the [Detection & Response API](../../../detection-response/api/#common-to-every-area).

**The record holds standing, not last contact.** It says whether the device is allowed in (`status`), not when it
was last heard from. `connected` is the one live signal: whether the device holds a session right now.

## Set it up

List the realm's devices ([Call the API](../../../develop/api/)):

```sh
curl https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1 \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
```

```json
[
  {
    "id": "<device id>",
    "uid": "maya-laptop",
    "status": "active",
    "os": "linux",
    "enrolledAt": "<RFC 3339 time>",
    "dar": { "agentId": "<sensor id>" },
    "connected": true
  }
]
```

Read one, and ask whether it's connected:

```sh
curl https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/<device id> \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"

curl https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/<device id>/connected \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
```

A read answers with an `ETag`, the record's revision. `connected` answers `{ "connected": true }` or `false`.

Record that the agent `invoice-agent` runs on the device, by the agent's id, and take it off again:

```sh
curl -X PUT https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/<device id>/agents/<agent id> \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"

curl -X DELETE https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/<device id>/agents/<agent id> \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
```

Both answer `204`.

## If it fails

| Status | When | What to do |
|---|---|---|
| `401` | No session, or it ended | Sign in again ([Call the API](../../../develop/api/)) |
| `403` | You lack `READ` (or `MODIFY`, to change) on the realm's endpoint settings | Ask a realm administrator to [grant it](../../api/#who-can-call) |
| `404` | No device with that id in this realm, or it has been removed | List the realm's devices for its id |
| `400` | The agent id isn't one of the realm's agents | Use the agent's `id` from [AI agents](../../../workforce-identity/agents/ai-agents/) |

## Limits and defaults

| What | Value |
|---|---|
| Devices listed | Every device of the realm, in one answer |
| Records per device | One; enrolling a device again makes a new one |
| Last contact | Not kept; `connected` is the state now |

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| `connected` reads `false` for a device you know is on | Under heavy load it can briefly read `false` | Ask again |
| The same device appears twice | It was enrolled again, which made a new record | Remove the older record ([Enroll a device again](../../guides/enroll-a-device-again/)) |
| `users` is empty | No one has approved the device for AI governance | Nothing to fix: `users` isn't who signs in on the device |

## Audit record

Changes to a device's record are recorded on the realm's audit trail with who made them: the record made at
enrollment (`CREATED`), an agent added or taken off (`UPDATED`), a revoke, restore or removal (`PATCHED`), and the
record going (`DELETED`). See [What is recorded](../../../audit-reports/audit-trail/what-is-recorded/). Reads are not
recorded.

## Good to know

- **Each realm sees its own.** A realm lists only its own devices. An administrator of a realm above it can reach
  the realms below; no one reaches another tree's.
- **Connected means now.** `connected` is the device's state now. Under heavy load it can briefly read `false` for a
  device that is connected; ask again.
- **Users are written by the AI fleet.** A user is added to `users` when they approve the device for AI governance,
  never by hand. It doesn't list everyone who signs in on the device.

## Reference

### Fields

| Field | What it holds |
|---|---|
| `id` | The device id |
| `uid` | The device's name, as its certificate carries it |
| `rev` | The record's revision, also its `ETag` |
| `status` | `active`, `revoked` or `removing` |
| `statusChangedAt` | When the status last changed |
| `revokedBy`, `reason` | Who revoked it and why, while it's revoked |
| `os` | The operating system it reported at enrollment |
| `enrolledAt` | When it was enrolled |
| `dar` | The security sensor: its sensor id (`agentId`) and its group |
| `users` | The users who approved it for AI governance |
| `agents` | The [AI agents](../../../workforce-identity/agents/ai-agents/) an administrator has recorded as running on it |
| `ppm` | Reserved for device policy, which is [planned](../whats-next/#os-policy-and-updates); not set today |
| `connected` | In a listing: whether its session is live right now |

## Related

- [Health and actions](../health-and-actions/): ask a connected device what it runs.
- [Device revocation](../../revoke-and-remove/revocation/) and [Device removal](../../revoke-and-remove/removal/):
  what changes `status`.
