AllTech
AllTech

Reputation: 603

How to find all users in a department in Microsoft Graph API V1.0

I am using below Microsoft Graph API api call to get Department name but using User id:

 var Peoples = await graphServiceClient.Users[user.Id].People.Request().GetAsync();
  foreach (Person People in Peoples)
                                        {
                                            if (People.DisplayName != null && People.DisplayName.Equals(user.DisplayName))
                                            {
                                                Console.Writeline(People.Department)

                                            }
                                        }

Now,i want to get all users in a Department(Where Department Name will be given as input) .

Please help.

Upvotes: 0

Views: 2371

Answers (1)

Kalyan Krishna
Kalyan Krishna

Reputation: 1714

You need to use the filter parameter.

the code will change to the following

 var Peoples = await graphServiceClient.Users.Request().Filter("department eq 'departname '").GetAsync();

Upvotes: 3

Related Questions