1
votes

I am trying to get all users from one AAD tenant with a specified schema extension. However, when doing this request:

GraphServiceClient client = new GraphServiceClient(new AuthProv(_authHelper.GetAuthenticationResult().Result));

  var userList = new List<User>();
  var users = await client.Users.Request().GetAsync();


  userList.AddRange(users.CurrentPage);
  while (users.NextPageRequest != null)
  {
    var nextPage = users.NextPageRequest.RequestUrl;
    Debug.WriteLine("Call To: " + users.NextPageRequest.RequestUrl);
    users = users.NextPageRequest.GetAsync().Result;
    userList.AddRange(users);
  }

I am receiving a JSON object that looks like:

[{"businessPhones":[],"displayName":"some account name","userPrincipalName":"somemail@email.com","id":"123","givenName":null,"jobTitle":null,"mail":null,"mobilePhone":null,"officeLocation":null,"preferredLanguage":null,"surname":null}, ...]

However, I have customized an own attribute for users so I can retrieve values from that, but that attribute is not sent with the API response.

How can I change the request so that all user attributes are retrieved as a reponse?

2

2 Answers

0
votes

It seems that you were using open extensions. If yes, we need to expand the extensions explicitly.

Here is the code to print the value of open extensions for your reference:

foreach (var user in users.CurrentPage)
{
    if (user.Extensions != null&& user.Extensions.CurrentPage!=null)
    {
        var customProperty = user.Extensions.CurrentPage.FirstOrDefault(ext => ext.Id == "Com.Contoso.Deal");
        if (customProperty != null)
            Console.WriteLine($"{user.UserPrincipalName}--{customProperty.Id}:{customProperty.AdditionalData["companyName"]}");
    }
}

while (users.NextPageRequest != null)
{
    var nextPage = users.NextPageRequest.RequestUrl;
    users = users.NextPageRequest.GetAsync().Result;
    foreach (var user in users.CurrentPage)
    {
        var customProperty = user.Extensions.CurrentPage.First(ext => ext.Id == "Com.Contoso.Deal");
        if (customProperty != null)
            Console.WriteLine($"{user.UserPrincipalName}--{customProperty.Id}:{customProperty.AdditionalData["companyName"]}");

    }
}

If there are multiple pages of open extension, you also should retrieve it via the NextPageRequest. Please feel free to let me know if you still have the problem.

1
votes

Use this new baseUrl: "https://graph.microsoft.com/beta/"

GraphServiceClient client = new GraphServiceClient("https://graph.microsoft.com/beta/",new AuthProv(_authHelper.GetAuthenticationResult().Result),null);