# Get started with Directory & Lifecycle

> Add your first user and your first group, put the user in the group, and read it back, in four calls.

In this page you add Maya to your realm, create an `engineering` group, and make her a member of it. From then on,
everything you give the group, such as an entitlement, a policy or a shared vault, reaches her, and leaves her the
moment she leaves the group.

## Before you begin

- **A realm administrator's account.** You need an account in a group that holds the realm's `RealmOwner`
  privilege. See [Delegated administration](../../platform/realms/delegated-administration/).
- **A session for the API.** Sign in as that administrator and keep the session in `$CVYUH_SESSION`, as
  [Call the API](../../develop/api/) describes. Every call below sends it as a cookie.
- **`curl`**, or any HTTP client. The calls use your realm's own host; replace `foobar` with your realm's.

## Add a user to a group

<Steps>

1. **Check your session.** Ask the realm who you are:

   ```sh
   curl -X POST https://foobar.cvyuh.com/api/v0/am/whoami/v1 \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
   ```

   The answer names you, your `roles` in the realm and how long the session has left (`session.expiresInSecs`). A
   `401` means the session has ended: sign in again.

2. **Add Maya.** Create a user, naming it `maya` with `?id=`, with her sign-in name in `uid` and a first password:

   ```sh
   curl "https://foobar.cvyuh.com/api/v0/am/objects/v1/user?id=maya" \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "uid": "maya", "firstName": "Maya", "lastName": "Chen", "displayName": "Maya Chen",
           "email": "maya@example.com", "passwordHash": "<a first password>" }'
   ```

   The realm answers `201` with her record:

   ```json
   {
     "id": "<internal id>",
     "objectId": "maya",
     "typeName": "user",
     "rev": <rev>,
     "attributes": { "uid": "maya", "displayName": "Maya Chen", "email": "maya@example.com",
                     "firstName": "Maya", "lastName": "Chen", "status": "active" },
     "createTime": "<RFC 3339 time>",
     "updateTime": "<RFC 3339 time>"
   }
   ```

   The realm filled `status` with `active`, and stored only a hash of her password, which no read returns.

3. **Create the group.**

   ```sh
   curl "https://foobar.cvyuh.com/api/v0/am/objects/v1/group?id=engineering" \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "displayName": "Engineering", "description": "Everyone who builds the product" }'
   ```

   The realm answers `201` with the group.

4. **Put Maya in the group.** Link her to the group's `member` list, naming her by her id:

   ```sh
   curl https://foobar.cvyuh.com/api/v0/am/objects/v1/group/engineering/relationships/member \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -H "If-Match: *" \
     -d '{ "targetId": "maya" }'
   ```

   The realm answers `201` with the link and the group's new revision:

   ```json
   { "_id": "engineering", "property": "member", "targetId": "maya", "rev": <rev> }
   ```

</Steps>

## Check it worked

Read Maya with her groups expanded:

```sh
curl "https://foobar.cvyuh.com/api/v0/am/objects/v1/user/maya?expand=memberOf/*" \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
```

Her `attributes.memberOf` lists one link, to `engineering`:

```json
"memberOf": [
  { "id": "<internal id>", "edgeId": "<internal id>", "properties": {},
    "objectId": "engineering", "type": "group",
    "object": { "displayName": "Engineering", "description": "Everyone who builds the product" } }
]
```

The link is stored once and read from both ends, so the group's `member` list holds Maya as well. Maya can now sign
in to the realm with `maya` and her password.

<Aside type="tip" title="Undo it">
  Remove her from the group with `DELETE` on
  `https://foobar.cvyuh.com/api/v0/am/objects/v1/group/engineering/relationships/member/maya`, and delete the user
  or the group with `DELETE` on its own address, each with `If-Match: *`.
</Aside>

## Next steps

<CardGrid>
  <LinkCard title="Add groups and members" description="What membership gives, and every way to change it." href="../groups/add-groups-and-members/" />
  <LinkCard title="Add your own attribute to users" description="Keep an employee number on every user, checked and searchable." href="../guides/add-an-attribute/" />
  <LinkCard title="Entitlements" description="Give the group what its members may do, for a window you set." href="../../workforce-identity/authorization/entitlements/" />
</CardGrid>
