Skip to content
Directory & LifecycleMarkdown

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.

  • Privilege: RealmViewer to 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.

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.

  1. 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 201 with the group and its revision, rev, also sent as the ETag header.

  2. 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 201 with { "_id": "engineering", "property": "member", "targetId": "maya", "rev": <rev> }. The same link made from the user’s side, on /objects/v1/user/maya/relationships/memberOf with { "targetId": "engineering" }, has the same effect.

  3. 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/*.

  4. 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.

WhatDefault or limit
Members of a groupNo fixed cap
Members listed per page20 unless you set pageSize, at most 100
Groups or members read inline with expandAt most 10,000; past that the read is refused 413, and you page the list instead
The same user linked twiceNot refused: a second link is made. Check before you link
NestingNone: a group’s members are users
AnswerCodeWhat it meansWhat to do
400INVALID_REQUESTThe body has no targetId, or the link is one a rule made (see Rule-based membership)Send { "targetId": "{id}" }; change the rule instead
403FORBIDDENYou may not change this group, or read the user you namedAsk for the privilege, or check the user id
404NOT_FOUNDNo such group, or no such link to removeCheck the ids
412REVISION_CONFLICTThe group changed since the revision you sent, or doesn’t exist under If-Match: *Read the group again

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.

SymptomCauseFix
A user is listed twice in a groupThe same link was made twice, for example by a load run againRemove the user (DELETE on …/relationships/member/{id}), check the list, and add them once
A member still has what the group gaveTheir app holds a token issued before the changeThe next token they get leaves it out; access tokens are short-lived
403 adding a user who existsYou may not read that userAsk an administrator whose privileges cover users
  • If-Match on a link guards the group. If-Match: "<rev>" refuses the change 412 if 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. PATCH the 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.
  • subscribable has 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.