ramizs
ramizs

Reputation: 13

Microsoft.Graph method of getByIds is not returning full objects containing all their properties

In my project, I was using GetByIds method of Microsoft.Graph API (link) with Select string, and it was working fine and was returning all the properties which are mentioned in the select string. But recently, it has stopped working and is not returning full objects containing all their properties provided in the select string. Even if I don't provide the Select, the properties are not returned fully, especially the ones I require like accountenabled, businessphones, city, companyname, country, department, jobtitle. This method is very crucial for my project and Microsoft has faulted it in their backend Microsoft.Graph APIs. Please, can someone help me in finding an alternative to this method which takes list of IDs of Users and return all their properties? Is there any ETA by Microsoft to fix this problem with this "GetByIds" method?

My code is as follows:

var directoryObjects = new List<Microsoft.Graph.DirectoryObject>();
var types = new List<String>()
            {
                "user"
            };
string select ="displayname,mail,mailnickname,onpremisessecurityidentifier,onpremisessyncenabled,proxyaddresses,id,odatatype,accountenabled,businessphones,city,companyname,country,department,givenname,imaddresses,jobtitle,mobilephone,onpremisesimmutableid,passwordpolicies,officelocation,postalcode,preferredlanguage,state,streetaddress,surname,usagelocation,userprincipalname,usertype";

var responseWithSelect = _graphServiceClient.DirectoryObjects.GetByIds(identitiesList,types).Request().Select(select).PostAsync().Result;

var responseWithoutSelect = _graphServiceClient.DirectoryObjects.GetByIds(identitiesList,types).Request().PostAsync().Result;

Upvotes: 1

Views: 1529

Answers (1)

Jack Jia
Jack Jia

Reputation: 5549

Just as the known issue shows:

Requesting objects using Get directory objects from a list of IDs should return full objects. However, currently user objects on the v1.0 endpoint are returned with a limited set of properties. As a temporary workaround, when you use the operation in combination with the $select query option, more complete user objects will be returned. This behavior is not in accordance with the OData specifications. Because this behavior might be updated in the future, use this workaround only when you provide $select= with all the properties you are interested in, and only if future breaking changes to this workaround are acceptable.

I used Fiddler to monitor the requests. And I found that the actually request was:

POST https://graph.microsoft.com/v1.0/directoryObjects/microsoft.graph.getByIds?$select=displayname,mail,mailnickname,onpremisessecurityidentifier,onpremisessyncenabled,proxyaddresses,id,odatatype,accountenabled,businessphones,city,companyname,country,department,givenname,imaddresses,jobtitle,mobilephone,onpremisesimmutableid,passwordpolicies,officelocation,postalcode,preferredlanguage,state,streetaddress,surname,usagelocation,userprincipalname,usertype HTTP/1.1
SdkVersion: Graph-dotnet-1.18.0
FeatureFlag: 0000004F
Cache-Control: no-store, no-cache
Authorization: Bearer eyJ0eXAiOiJKV1Qi*****************X5Q
Accept-Encoding: gzip
Content-Type: application/json
Host: graph.microsoft.com
Content-Length: 65
Expect: 100-continue

{"ids":["ab6d4cd6-fc2d-40c7-a676-f8773aebfb5f"],"types":["user"]}

However, in the response, not all the required properties were returned. Even displayname was not returned. I checked further, and I find the actual property name is displayName. So, I changed it to the right one, and I was able to get the displayName returned.

So,

  1. the API itself has some known issues which prevents it from returning requested values.

  2. the select string is case sensitive now.

You may change your codes accordingly to see if it helps.

Upvotes: 1

Related Questions