Add groups and members
Create groups, add and remove their members from either side, and list who's in them.
AvailableAPI
Create a group, put users in it, and everything the group holds reaches them. Membership is one link, readable and changeable from the group or from the user, so a user’s groups and a group’s members never disagree.
Before you begin
Section titled “Before you begin”- Privilege:
RealmViewerto list groups and members;RealmOwner, or a privilege of your own over groups, to create groups and change members. See Who may do what. - Where: the API, with your session in
$CVYUH_SESSION(see Call the API). - The user exists before you add them to a group.
How it works
Section titled “How it works”Every group is an object of the group type. Its id is its name, such as engineering, and it carries a
displayName, a description, and its members.
Membership is a link between a group and a user, stored once and readable from both ends: the group lists the
user in member, and the user lists the group in memberOf. Add or remove a link from either side and both ends
change together, in one step. Membership is a list of links, not a stored copy of names, so a user renamed or
deleted never leaves a stale entry behind.
A group can also hold entitlements of its own in grants, each for a window you set, and effectiveGrants shows
the ones in effect right now. See Entitlements.
Set it up
Section titled “Set it up”-
Create the group:
Terminal window 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
201with the group and its revision,rev, also sent as theETagheader. -
Add a member, naming the user by id:
Terminal window 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
201with{ "_id": "engineering", "property": "member", "targetId": "maya", "rev": <rev> }. The same link made from the user’s side, on/objects/v1/user/maya/relationships/memberOfwith{ "targetId": "engineering" }, has the same effect. -
List the members:
Terminal window curl https://foobar.cvyuh.com/api/v0/am/objects/v1/group/engineering/relationships/member \-H "Cookie: x-cvyuh-token=$CVYUH_SESSION"The list pages like any other (see Search and paging). To see one user’s groups, read the user with
?expand=memberOf/*. -
Remove a member:
Terminal window curl -X DELETE https://foobar.cvyuh.com/api/v0/am/objects/v1/group/engineering/relationships/member/maya \-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \-H "If-Match: *"The user loses what the group gave them from their next request.
Limits and defaults
Section titled “Limits and defaults”| What | Default or limit |
|---|---|
| Members of a group | No fixed cap |
| Members listed per page | 20 unless you set pageSize, at most 100 |
Groups or members read inline with expand | At most 10,000; past that the read is refused 413, and you page the list instead |
| The same user linked twice | Not refused: a second link is made. Check before you link |
| Nesting | None: a group’s members are users |
When a change fails
Section titled “When a change fails”| Answer | Code | What it means | What to do |
|---|---|---|---|
400 | INVALID_REQUEST | The body has no targetId, or the link is one a rule made (see Rule-based membership) | Send { "targetId": "{id}" }; change the rule instead |
403 | FORBIDDEN | You may not change this group, or read the user you named | Ask for the privilege, or check the user id |
404 | NOT_FOUND | No such group, or no such link to remove | Check the ids |
412 | REVISION_CONFLICT | The group changed since the revision you sent, or doesn’t exist under If-Match: * | Read the group again |
Audit record
Section titled “Audit record”Adding or removing a member is recorded as UPDATED on the group, with the link in edgeChanges (added or
removed) and who made it. It’s in the group’s change history:
see See who changed a group.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause | Fix |
|---|---|---|
| A user is listed twice in a group | The same link was made twice, for example by a load run again | Remove the user (DELETE on …/relationships/member/{id}), check the list, and add them once |
| A member still has what the group gave | Their app holds a token issued before the change | The next token they get leaves it out; access tokens are short-lived |
403 adding a user who exists | You may not read that user | Ask an administrator whose privileges cover users |
Good to know
Section titled “Good to know”If-Matchon a link guards the group.If-Match: "<rev>"refuses the change412if the group was changed since you read it;If-Match: *asks only that the group exists.- Linking reads the user. You can add only a user you’re allowed to read; for any other, the realm refuses before it says whether that user exists.
- Leaving every group at once.
PATCHthe user with{ "memberOf": [] }, and each of their groups stops listing them in the same write. - Deleting a group removes every link to it. Its members lose what it gave them, and the secrets in its vault go with it (see Deleting an owner). The users themselves are untouched.
- Groups don’t nest. A group’s members are users; a group can’t be a member of another group.
subscribablehas no effect yet. The shipped group carries it, for groups users will join themselves, but nothing reads it today. See What’s next for groups.
Related
Section titled “Related”- Get started with Directory & Lifecycle: a user and a group, end to end.
- Rule-based membership: membership worked out from a rule.
- Share secrets with a team: a group’s own vault.