How-To: Manage Users using GraphQL

Last Updated: 2021-11-11

There are two options to automate or script users and group operations:

  • Using the GraphQL API which this document describes

  • Using humiocti

It's possible to do all steps either in the UI or with the GraphQL API or Humio CLI.

Note

On Humio Cloud, users are invited and marked as pending users when completed from the UI

You can use the API explorer to perform these queries directly within the Humio UI.

Creating A User

graphql
mutation {
 addUserV2(input:{
 username:"a_new_user@example.com",
 email: "a_new_user@example.com",
 company:"example.com"}) {
 __typename
 }
}

Get User and ID

graphql
query {
 usersPage(
 pageSize:1000,
 search: "a_new_user@example.com",
 pageNumber:1) {
 page {
 id
 username
 }
 }
}

Create A Group

graphql
mutation {
 addGroup(displayName:"testgroup", lookupName: "optional_idp_group_name") {
 group {
 id
 }
 }
}

Get Group ID

graphql
query {
 groupsPage(search: "testgroup", pageNumber:1, pageSize:100) {
 page{
 id
 displayName
 }
 }
}

Get a list of Repositories and Views

graphql
query {
 searchDomains {
 id
 name
 }
}

Get ID for a Role

graphql
query {
 roles {
 id
 displayName
 }
}

Add a Repository to a Group with a Role

Here we need to run two mutations, one to assign the role to the group, then add the repository to the group

graphql
mutation {
 assignRoleToGroup(input:{
 viewId: "smX0nAvLufBfD8ne52FEiZar",
 groupId:"aID9ijJg0Q9vewrlz7PCILrwj1VuGz3D",
 roleId:"l18cgJhRbT8HcNwyuTDbStRe6zpb0c3w"}){
 group {
 role {
 id
 }
 }
 }
}
graphql
mutation {
 updateQueryPrefix(input:{
 queryPrefix:"*",
 viewId:"smX0nAvLufBfD8ne52FEiZar",
 groupId: "aID9ijJg0Q9vewrlz7PCILrwj1VuGz3D"}) {
 group {
 id
 }
 }
}

Assign a user to a group

graphql
mutation {
 addUsersToGroup(input:{
 users:["4UA84wRdGJV7pFPzh4Hn5wWQ"],
 groupId: "aID9ijJg0Q9vewrlz7PCILrwj1VuGz3D"}) {
 group {
 id
 }
 }
}

Unassign a user from a group

graphql
mutation {
 removeUsersFromGroup(input:{users:["4UA84wRdGJV7pFPzh4Hn5wWQ"], groupId:"aID9ijJg0Q9vewrlz7PCILrwj1VuGz3D"}) {
 group {
 id
 }
 }
}

Delete a user

graphql
mutation {
 removeUserById(input:{id:"4UA84wRdGJV7pFPzh4Hn5wWQ"}) {
 user {
 id
 }
 }
}