User Groups
API

User Groups API

Introduction

We usually interpret a user group as precisely what the name says: a group of users. For example, you may want to group users by their home country or any other characteristic. Read more about this topic in the user group feature guide.

Mutations

createUserGroup()

To create a user group, you simply need to define a name and reference.

await client.asSuperAdmin().createUserGroup(
  { userGroup: 
      { name: 'xyz789', reference: 'xyz789' }
  }
);
ParameterTypeDescription
namestringThe name of the user group. For instance “My Team”
referencestringReference to an object on the project-side. This could be the ID of an entity in your database

addUsersToUserGroup()

To add users to a user group, you can use this mutation:

await client.asSuperAdmin().addUsersToUserGroup(
  { userGroupId: "abc123", 
    userIds: ["abc123", '321cba'] 
  }
);

Queries

userGroups()

To see user groups with users you run a query like this:

await client.asSuperAdmin().userGroups({ 
  withUsers: true 
});

Another way to fetch users by a user group could look like:

await client.asSuperAdmin().users({ filter: { 
    userGroupId: {equalTo: "123" } 
    } 
});