How to search users in Microsoft Graph SDK with C#?

Viewed 7119

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

2 Answers

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.

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

Related