# Directory & Lifecycle API

> Every endpoint of the directory on your realm's own host, by area, with what each one does and the page that covers it.

Every directory endpoint is on your realm's own host, under `https://foobar.cvyuh.com/api/v0/am`, and takes a
session in the `x-cvyuh-token` cookie. How to get one, and the conventions every call shares (paging, revisions,
errors), are in [Call the API](../../develop/api/). `{type}` is `user`, `group`, `agent` or a type of your own; `{id}` is
an object's id, such as `maya`.

Reads (`GET`, `QUERY`) need `RealmViewer`; every other call needs `RealmOwner`, or a privilege of your own that
covers it (see [Who may do what](../attributes/identity-model/#who-may-do-what)); the self-service calls need only the
user's own session. Lists page 20 at a time, at most 100; `expand` returns at most 10,000 links per attribute; a body
may be about 2 MB. There's no rate limit today. Every refusal answers `{ "code", "message", "detail" }`: see
[When a call fails](../attributes/identity-model/#when-a-call-fails).

## Users, groups and agents

Users, groups, agents and your own types are all objects, at the same addresses.

| Method | Endpoint | What it does | Page |
|---|---|---|---|
| `GET` | `https://foobar.cvyuh.com/api/v0/am/objects/v1/{type}` | List and search the objects of a type, a page at a time | [Search and paging](../users/search/) |
| `QUERY` | `https://foobar.cvyuh.com/api/v0/am/objects/v1/{type}` | The same search, with its parameters in a JSON body | [Search and paging](../users/search/) |
| `POST` | `https://foobar.cvyuh.com/api/v0/am/objects/v1/{type}?id={id}` | Create an object; leave out `id` and the realm picks one | [Add and change users](../users/add-and-change-users/) |
| `GET` | `https://foobar.cvyuh.com/api/v0/am/objects/v1/{type}/{id}` | Read an object; `?expand=` adds its links | [Add and change users](../users/add-and-change-users/) |
| `PATCH` | `https://foobar.cvyuh.com/api/v0/am/objects/v1/{type}/{id}` | Change the attributes you send: a merge patch, or a JSON Patch list | [Add and change users](../users/add-and-change-users/) |
| `PUT` | `https://foobar.cvyuh.com/api/v0/am/objects/v1/{type}/{id}` | Replace every attribute; with `If-None-Match: *`, create | [The identity model](../attributes/identity-model/) |
| `DELETE` | `https://foobar.cvyuh.com/api/v0/am/objects/v1/{type}/{id}` | Delete an object and every link to it | [Add and change users](../users/add-and-change-users/) |
| `GET` | `https://foobar.cvyuh.com/api/v0/am/objects/v1/{type}/{id}/history` | Every change to the object, newest first | [The identity model](../attributes/identity-model/#every-change-is-recorded) |

The answer to a read or a write is the object: `id`, `objectId`, `typeName`, `rev`, `attributes`, `createTime` and
`updateTime`, with `rev` also in the `ETag` header. A list answers `data` with `page`, `pageSize`, `totalCount`,
`totalPages`, or `hasMore` and `nextCursor` when paging by cursor.

## Links

Group membership, agent ownership and every other link, made and read from either end.

| Method | Endpoint | What it does | Page |
|---|---|---|---|
| `GET` | `https://foobar.cvyuh.com/api/v0/am/objects/v1/{type}/{id}/relationships/{link}` | List an object's links of one kind, such as a group's `member`, paged and filtered | [Add groups and members](../groups/add-groups-and-members/) |
| `POST` | `https://foobar.cvyuh.com/api/v0/am/objects/v1/{type}/{id}/relationships/{link}` | Make a link, with `{ "targetId": "{id}" }` and any link `properties` | [Add groups and members](../groups/add-groups-and-members/) |
| `DELETE` | `https://foobar.cvyuh.com/api/v0/am/objects/v1/{type}/{id}/relationships/{link}/{target id}` | Remove a link | [Add groups and members](../groups/add-groups-and-members/) |

A link answers `201` with `{ "_id", "property", "targetId", "rev" }`, `rev` being the object's new revision. A
listed link is `{ "id", "edgeId", "properties" }`: the far object's id, the link's own id, and the link's properties.

## Attributes and types

| Method | Endpoint | What it does | Page |
|---|---|---|---|
| `GET` | `https://foobar.cvyuh.com/api/v0/am/types/v1` | List the realm's types, paged and searchable | [The identity model](../attributes/identity-model/) |
| `POST` | `https://foobar.cvyuh.com/api/v0/am/types/v1` | Define a type of your own | [Custom types](../attributes/custom-types/) |
| `GET` | `https://foobar.cvyuh.com/api/v0/am/types/v1/{type}` | Read a type's whole definition, with its `rev` | [Attributes and validation](../attributes/attributes-and-validation/) |
| `PUT` | `https://foobar.cvyuh.com/api/v0/am/types/v1/{type}` | Replace a type's definition, with `If-Match` | [Attributes and validation](../attributes/attributes-and-validation/) |
| `GET`, `PATCH` | `https://foobar.cvyuh.com/api/v0/am/objects/v1/identityBinding/identityBinding` | Read or change which types are users, groups and agents | [Your own user type](../attributes/your-own-user-type/) |

A type is never patched (`PATCH` answers `405`) and never deleted (`DELETE` answers `405`).

## Self-service

Called with the user's own session, for their own account.

| Method | Endpoint | What it does | Page |
|---|---|---|---|
| `POST` | `https://foobar.cvyuh.com/api/v0/am/whoami/v1` | Who the caller is: profile, roles in the realm, and session | [Self-service](../users/self-service/) |
| `GET` | `https://foobar.cvyuh.com/api/v0/am/devices/v1` | The caller's passkeys, authenticator apps and recovery codes; `?kind=` for one kind | [Self-service](../users/self-service/) |
| `DELETE` | `https://foobar.cvyuh.com/api/v0/am/devices/v1/{id}` | Remove one of the caller's passkeys or authenticator apps | [Self-service](../users/self-service/) |

The apps and agents a user allowed are in the [Customer Identity API](../../customer-identity/api/).

## Lifecycle

| Method | Endpoint | What it does | Page |
|---|---|---|---|
| `POST` | `https://foobar.cvyuh.com/api/v0/am/sessions/v1/end` | End every session a filter matches, such as a leaver's | [Offboard a leaver](../guides/offboard-a-leaver/) |
| `GET` | `https://foobar.cvyuh.com/api/v0/am/sessions/v1` | List live sessions, filtered by user | [Offboard a leaver](../guides/offboard-a-leaver/) |

Starting, moving and stopping a user are writes to their record and their links, above; see
[Joiners, movers and leavers](../lifecycle/joiners-movers-leavers/).
