AllTech
AllTech

Reputation: 603

How to get all departments in an organization using MS Graph API

I am using below code to find department name:

GraphServiceClient graphServiceClient = connectToGraphAPI(Globals.adTenantId, Globals.adClientId, Globals.adClientSecret);

var Peoples = await graphServiceClient.Users[userid].People.Request().GetAsync();
foreach (Person People in Peoples) {
    if (People.DisplayName != null && People.DisplayName.Equals(userName)) {
        return People.Department.ToString();
    }
}

But, I want to get list of all departments in an organization rather than finding Departments of specific user.

Upvotes: 3

Views: 3361

Answers (1)

Tony Ju
Tony Ju

Reputation: 15629

Just like @Matt.G said, Department is a string value under the Job Info section on the User-Profile page. There is no api to list all departments in an organization. You need to loop through users to fetch departmentName.

Upvotes: 6

Related Questions