Managing groups & group members via API

 

The new user management UI enables you to assign users to groups. But creating new groups is currently not available via UI. So this is a guide which leads you through the calls needed for it.

Preferences

  • Token of a user / service-user which has admin role (chat.admin.all) assigned → <yourToken>

  • The base URL of your application → <baseUrl>

Check here how to get a token: How to get a Token for our APIs

Fetching groups

With the following cURL you can fetch all available groups of the organisation the user/service-user belongs to. Just replace the following placeholders: <baseUrl> / <yourToken>

curl --location 'https://gateway.<baseUrl>/scope-management/graphql' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer <yourToken>' \ --data '{"query":"query AllGroups {\n allGroups {\n id\n name\n parentId\n createdAt\n updatedAt\n }\n}","variables":{}}'

This should give you the following result:

{ "data": { "allGroups": [ { "id": "group_123456789032eqd21xocgdfw", "name": "Root Group", "parentId": null, "createdAt": "2021-05-17T10:35:30.212Z", "updatedAt": "2021-09-23T09:36:11.846Z" }, { "id": "group_0987654321jviq7tiure95uh", "name": "GPT-4 Group", "parentId": "group_123456789032eqd21xocgdfw", "createdAt": "2021-05-20T08:54:10.839Z", "updatedAt": "2021-05-20T08:54:10.839Z" }, ... ] } }

 

As you can see the groups can be hierarchical. This is something to keep in mind when creating new groups.

Creating a group

Before creating a group you need to know how you want to organise your organisation/company. As default there is a Root Group created where all users (also new ones) get assigned on signup. Groups can be hierarchical. Imagine a setup where you have the Root Group and create a new group with IT and the parent is the Root Group and another group called Development with the parent IT. People added as member to the group Development will automatically also gain access to the scopes/spaces of this group itself and all parent groups. With this setup you are able to replicate the organisation chart of your company and manage access. Its also possible to have a flat hierarchy of groups with multiple “root groups” and no parents or children.

Now lets create a group. This can be done with this cURL. Just replace the following placeholders: <baseUrl> / <yourToken> / <groupName> / <parentId>

curl --location 'https://gateway.<baseUrl>/scope-management/graphql' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer <yourToken>' \ --data '{"query":"mutation CreateGroup($input: GroupCreateInput!) {\n createGroup(input: $input) {\n id\n name\n parentId\n }\n}","variables":{"input":{"name":"<groupName>","parent":{"connect":{"id":"<parentId>"}}}}}'

If you want to make the flat hierarchy (multiple “root groups”) then you can leave out the part with the parent. Doing it like this:


This should respond with the following successful response with your replaced <groupName>, a new unique <groupId> and if you did it hierarchical the <parentId> otherwise null:

Now this group is visible in the UI and users with the user management permission are able to assign and remove users from this new group.

Updating Groups

In case you did a typo or a name of a group changed you can update an existing group with the following cURL. Just replace the following placeholders: <baseUrl> / <yourToken> / <groupId> (ID of the group you want to change) / <groupName> (new name you want to set)

This should give you the following result:

 

Updating Metadata

The same cURL command can be used to add/update metadata to a group. The metadata can be passed within the parameter named configurationin the input object.

Below you can see an example where the metadata with key location with a value switzerland is added to the group specified with <groupId>.

 

Deleting Groups

A group can be delted as follows, make sure the groups do not have members anymore.

Conclusion

Now you should be able to fetch, create and update groups via the API.


Author

@Adrian Gugger

 

© 2024 Unique AG. All rights reserved. Privacy PolicyTerms of Service