Yash
Yash

Reputation: 191

Microsoft graph api returning NULL in Department field

I have given all required permissions for retrieving user info from Azure active directory like User.Read.All and User.Read but still getting Department and EmployeeId field as NULL

code used:

public Microsoft.Graph.User GetUser(ref GraphServiceClient graphServiceClient, string UserId)
    {
        return graphServiceClient.Users[UserId].Request().GetAsync().Result;

    }

Upvotes: 0

Views: 1633

Answers (1)

user2250152
user2250152

Reputation: 20748

According to the documentation both department and employeeId are returned only on $select.

Use Select method and specify those two properties. If you need to return more properties, they need to be specified in Select. Without using Select, Graph API return only default set of properties.

public Microsoft.Graph.User GetUser(ref GraphServiceClient graphServiceClient, string UserId)
{
    return graphServiceClient.Users[UserId]
             .Request()
             .Select("department,employeeId")
             .GetAsync()
             .Result;
}

Resources:

Select parameter

Upvotes: 2

Related Questions