# Endpoint Management API

> Every endpoint Endpoint Management serves on your realm's host, by area, with the page that explains each.

Every call here is made on your realm's own host with a realm administrator's session, sent as the
`x-cvyuh-token` cookie; [Call the API](../../develop/api/) shows how to get one.

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

## Who can call

Endpoint Management is administered through the realm's endpoint settings. Reads need `READ` on them, and every change
(a token, an action, a revoke, a removal) needs `MODIFY`:

| Privilege | Holds | Can |
|---|---|---|
| `RealmOwner` | `READ`, `MODIFY` | Everything on this page |
| `RealmViewer` | `READ` | List and read devices, and read the system inventory and settings; none of the changes on this page |

Both reach the realm they're held in and every realm beneath it. Realm administrators hold `RealmOwner`. To let
someone else run the realm's devices, put them in a group and grant the group `RealmOwner`, or `RealmViewer` to let
them only look; see [Delegated administration](../../platform/realms/delegated-administration/). A narrower
privilege of your own can grant `READ` and `MODIFY` on the realm's endpoint settings alone
([Roles of your own](../../platform/realms/delegated-administration/#roles-of-your-own)). Only an administrator of the
root realm can change the device cap.

A call without a session is answered `401`; one without the privilege, `403`.

## Enrollment

| Method | Endpoint | What it does | Page |
|---|---|---|---|
| `POST` | `https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/enrolment-tokens` | Make a one-time enrollment token | [Device enrollment](../enrollment/device-enrollment/) |
| `GET` | `https://foobar.cvyuh.com/api/v0/am/objects/v1/endpointSettings/endpointSettings` | Read the device cap and the token lifetime | [Device limits](../enrollment/device-limits/) |
| `PATCH` | `https://foobar.cvyuh.com/api/v0/am/objects/v1/endpointSettings/endpointSettings` | Change the token lifetime (and, from the root realm, the device cap) | [Device limits](../enrollment/device-limits/) |

`POST .../enrolment-tokens` (spelled that way) takes `{ "ttlHours": <hours> }`, optional, and answers `201` with
`{ "token", "expiresAt" }`, or `400` for a lifetime outside 1 hour to the realm's setting.

## Devices

| Method | Endpoint | What it does | Page |
|---|---|---|---|
| `GET` | `https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1` | List the realm's devices, each with `connected` | [Device records](../devices/device-records/) |
| `GET` | `https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/{device}` | Read one device's record, with its `ETag` | [Device records](../devices/device-records/) |
| `GET` | `https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/{device}/connected` | Whether the device's session is live now | [Device records](../devices/device-records/) |
| `POST` | `https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/{device}/do` | Run an action on the device: `report`, `status` or `restart-dar` | [Health and actions](../devices/health-and-actions/) |
| `PUT` | `https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/{device}/agents/{agent}` | Record that an agent runs on the device | [Device records](../devices/device-records/) |
| `DELETE` | `https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/{device}/agents/{agent}` | Take the agent off the device | [Device records](../devices/device-records/) |
| `PUT` | `https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/{device}/users/{user}` | Add a user to the device; made by the realm's AI fleet when a user approves the device, not by administrators | [AI governance sign-in](../../ai-governance/fleet/user-sign-in/) |
| `DELETE` | `https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/{device}/users/{user}` | Take a user off the device; reserved for the AI fleet, which doesn't call it yet, so a user once added stays listed | [AI governance sign-in](../../ai-governance/fleet/user-sign-in/#limits-and-defaults) |

`{device}` is the device id, the record's `id`. `POST .../do` takes `{ "kind": "report" }` and answers
`{ "id", "ok", "detail" }` within 30 seconds; `503` when the device isn't connected, and `504` when it didn't answer
in time.

The device's [System inventory](../devices/system-inventory/) is read through the security log's API; see
[Detection & Response API](../../detection-response/api/).

## Revoke and remove

| Method | Endpoint | What it does | Page |
|---|---|---|---|
| `PUT` | `https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/{device}/revocation` | Revoke the device: every stream it holds closes | [Device revocation](../revoke-and-remove/revocation/) |
| `DELETE` | `https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/{device}/revocation` | Restore the device | [Device revocation](../revoke-and-remove/revocation/) |
| `DELETE` | `https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/{device}` | Remove the device for good; answers `202` | [Device removal](../revoke-and-remove/removal/) |

`PUT .../revocation` takes `{ "reason": "<text>" }`, optional. All three take an optional `If-Match` with the
record's `ETag`, and answer `412` when the record changed since.

## Good to know

- **Your session is the only credential.** Calls to the security log and the AI fleet are made on your own session.
  The short-lived credentials the realm uses behind them never leave the realm, and are revoked when your session
  ends.
- **Every change is on the audit trail.** Changes to device records and to the endpoint settings are recorded with
  who made them; actions and reads are not. See [What is recorded](../../audit-reports/audit-trail/what-is-recorded/).
- **One device per call.** Each call here acts on one device.
