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.