# Add users and groups

> Create your first users, put them in their groups, and see one of them sign in, in about ten minutes.

Your engineering and finance teams are starting to use the realm. You add Maya and Ben, create an `engineering` and a
`finance` group, put each of them in theirs, and check that Maya can sign in. Everything you give a group from then
on reaches its members.

**Before you start:** you're a realm administrator holding `RealmOwner`, with your session in `$CVYUH_SESSION` (see
[Call the API](../../../develop/api/)).

## Add them

<Steps>

1. Create Maya, naming her `maya`, with 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. Her password isn't in it: the realm stored only a hash of it.

2. Create Ben the same way, with `?id=ben` and his own details.

3. Create the groups:

   ```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" }'

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

4. Put each of them in their group:

   ```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" }'
   ```

   Then the same on `/objects/v1/group/finance/relationships/member` with `{ "targetId": "ben" }`. Each answers
   `201`.

</Steps>

<Aside type="tip" title="Many users at once">
  For more than a handful, script these calls from a file. To bring users from a system you already run, with their
  passwords, see [Bring users from another system](../bring-users-from-another-system/).
</Aside>

## Check it worked

Read Maya with her groups:

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

`engineering` is in her `memberOf`, and her `status` is `active`, filled in by the realm. Then have Maya sign in to
the realm with `maya` and her password. She's in.

## Undo it

Remove a member with `DELETE` on `/objects/v1/group/engineering/relationships/member/maya`. Delete a user or a group
with `DELETE` on `/objects/v1/user/{id}` or `/objects/v1/group/{id}`, each with `If-Match: *` or the revision you
read.

## Related

- [Add and change users](../../users/add-and-change-users/): every attribute a user has.
- [Add groups and members](../../groups/add-groups-and-members/): what membership gives, and where groups are used.
- [Add your own attribute to users](../add-an-attribute/): keep an employee number or a department.
- [Entitlements](../../../workforce-identity/authorization/entitlements/): give the group what its members may do.
