5

In my C# application, I am using Microsoft Graph SDK with Azure AD implementation.

Please suggest me how to search users in my organisations (global contacts) based on search parameters . For example , if "Raj" is the search parameter, I should be able to get all users with their name contains "Raj" or email address contains "Raj". I found this method to get all users - "graphClient.Users.Request().GetAsync();". but, with this method limited response, I am not getting what exactly I want to search.

Thanks, Shashidhar

Shashi1988
  • 61
  • 1
  • 3

3 Answers3

15

Adding to the previous answer: to accomplish this through the Graph C# SDK, use the Filter() method:

graphClient.Users.Request().Filter("startsWith(displayName, 'k')").GetAsync()

You can use other methods on the request to customize the request, e.g. Select(), etc.

Mustapha Larhrouch
  • 3,373
  • 3
  • 14
  • 28
Peter Ciszewski
  • 609
  • 3
  • 6
4

According to your description, I assume you want to search the users by using the search parameters.

Based on this document, we can currently search only message and person collections.

And I have tried the filter query parameter, the parameter is currently not supported the contains operator from this document. So if you want to search the user with name or the email address, we can use the startswith operator only.Like this:

https://graph.microsoft.com/v1.0/users?$filter=startswith(displayName,'k') or startswith(mail,'k')

It will find the user's diplayName or mail which is start with the k

Keen Jin
  • 1,060
  • 1
  • 6
  • 8
1
 var queryOptions = new List<Option>() 
            { 
                new QueryOption("ConsistencyLevel", "eventual") ,
                new QueryOption("$search", "\"displayName:fis\"") 
            };

            GraphServiceClient graphServiceClient = serviceProvider.GetRequiredService<GraphServiceClient>();

            var users = await graphServiceClient.Users
                .Request(queryOptions)
                .WithAppOnly()
                .GetAsync();
Sebastian
  • 11
  • 1