How should I request the User
employeeOrgData.division
using the Microsoft Graph SDK?
Here’s my code…
[AuthorizeForScopes(Scopes = new[] { "User.Read.All" })]
public async Task<IActionResult> GridView()
{
var queryOptions = new List<QueryOption>();
queryOptions.Add(new QueryOption("$count", "true"));
queryOptions.Add(new QueryOption("$expand", "manager($levels=1;$select=displayName)"));
queryOptions.Add(new QueryOption("$select", "onPremisesSamAccountName,displayName,mail,jobTitle,department,surname,givenName,streetAddress,city,state,postalCode,businessPhones,mobilePhone,employeeOrgData.division"));
var results = await _graphServiceClient.Users
.Request(queryOptions)
.Header("ConsistencyLevel", "eventual")
.Filter("employeeType eq 'Employee'")
.GetAsync();
//CONCATENATES THE PAGED RESULTS
var users = new List<User>(results.CurrentPage);
users.AddRange(results.CurrentPage.OfType<User>());
while (results.NextPageRequest != null)
{
results = await results.NextPageRequest.GetAsync();
users.AddRange(results.CurrentPage.OfType<User>());
}
//SORT BY LAST, FIRST
users = users
.DistinctBy(u => u.Id)
.OrderBy(x => x.Surname)
.ThenBy(x => x.GivenName).ToList();
return View("GridView", users);
}
I’ve tried selecting both employeeOrgData
and employeeOrgData.division
. In both cases it’s always null.
I’ve tried expanding employeeOrgData
, but it’s not exapandable.