GraphQL User Queries

Summary

As with any software system that is used by several people and applications, LogScale has user accounts which provide access and permissions for users to get and change data. Therefore, some of the most often used queries relate to user accounts.

To learn how to use the GraphQL API, you should learn about user related queries. This page explains a few of the most common ones, while assuming no familiarity with this API, but that you have already learned to log into the LogScale UI.

Know Yourself

To begin, let's get information on yourself, on your user account. Although you may have provided the initial values for your account, there will invariably be some values that are assigned to you by the default system settings and by an administrator. The currentUser() query will return such information. Here's the syntax for it:

graphql
currentUser: User!

There's no input for this query. None is needed. There is only one current user for a login. For the returned values, it uses the User datatype. Through it, you can get a tremendous amount of information on a user account. To start, though, here's a simple use of the query:

graphql
query {
	 currentUser {
       id, username
   }

This will return the user's unique identfier, which is required by some other queries, and the login user name. To try this, use the API Explorer to enter this query — copy and paste it.

Let's use the same query to get more information:

graphql
query {
	 currentUser {
       id, username, 
       groupsV2( limit: 2 ) { results { displayName } } 
     }
   }

This will return the same information on the current user, but also provide a list groups to which the user belongs. Since the limit is set to 2, only two groups will be returned. Here's how the results of this query might look:

graphql
{
  "data": {
    "currentUser":
      {
        "id": "abc123",
        "username": "bobsmith",
        "groupsV2": { 
           "results": [ {
              "displayName": "sales" 
              },
              {
              "displayName": "managers" 
              } ]
        } 
      } 
   }
}

Notice that the list of user groups is contained within square-brackets, like an array.

Others

It's not enough to be able to get information on your own user account. You'll need to know how to get data on other users. For that you can use the users() query. Below is the syntax for it:

graphql
users(
     search: string,
     orderBy: OrderByUserFieldInput
   ): [User]!

There are two optional input parameters. The first allows you to provide a search string to limit results (e.g., you might search for a certain name). The second allows you to specify some ordering parameters.

For the results, the query uses the same datatype as the earlier query, but this time it's contained in square-brackets. You don't enter them. They indicate that an array of results will be returned — which will be within square-brackets.

Here's an example using this query with the two input parameters:

graphql
query{
     users(
       search: "company.com",
       orderBy: {userField: USERNAME, order: ASC}
     )
     {username, email, displayName}
}

Notice that the query says to search for users with an email address that contains the company domain name. It's also ordering based on user names, in ascending order. For the results, it will return the user name, email address, and a more human-friendly version of the name (e.g., Robert Smith for bobsmith), if one has been entered.

More on One

Although the users() query can provide plenty of information on each user, and you can filter results, it can return too much for a large organization, especially if you want more than a few fields of data on each user.

Once you've searched all users and narrowed the results with the search parameter, you can take the unique identifier for a particular user and use the user() query. Here's its syntax:

graphql
user(
     id: string!
   ): User

For this query's results, you can request the same return values as with the users() query, except since it's for only one user, you might request more values. Here's an example:

graphql
query{
     user( id: "abc123" ) 
     { username, displayName, email,
       groupsV2 { results { displayName } } 
       allowedSystemActions,
       isOrgRoot, permissions { viewPermissions }
      }
   }

As you can see, the possibilities are extensive. There are many more choices, and sub-choices for a user.

Conclusion

There are a few other queries specifically for users. Common to them all is the User datatype. Reusing special datatypes is part of the efficiency and dynamic of LogSCale. Get to know this datatype; learn what's possible with it.

There are a couple other tutorials on queries you might find useful. One is on querying repositories. The other is on groups and roles, which relates to users.