Microsoft Graph REST API Bug When Applying a $select=id

As you all have noticed by now, I have been exploring implementing the Graph REST API to interact with Outlook components: E-mail, Calendar, Contacts, …

 

Well, I’ve encountered an oddity that I qualify as a bug.  I’m still investigating, bug have been able to reproduce the issue multiple times now (every time in fact).

The Bug

If you follow the documentation, you will see that it is a best practice to apply filters and select on your requests to minimize the data being pushed and pulled.  For anyone having done SQL work, this makes perfect sense.

I have been working on a couple routines to retrieve a contact’s id, or a contact folder’s id and as such was applying a select like:

$select=id

However, in testing via VBA, this always returned a single value in the response, even when multiple matching values existed.

Furthermore, this seems to be solely when applying a $select=id. If I apply a $select to another column, it then works as expected.

However, being the id is the ‘PK’ driving everything, this poses a real issue!

The Workaround

The ‘fix’ that I’ve found is that it is necessary to include 1 more column, any column! So for a contact, I now do

$select=id,givenName

and now suddenly I get 3 ids returned whereas previously I only got 1?!

Even Weirder

What baffles me even more is the fact that if I test in the Graph Explorer the original URL/select, so:

$select=id

it works fine, and return all 3 ids.

I figured I’d at least share here and hopefully avoid some frustrations for any of you exploring all of this.

Bug Or No Bug, The Root Cause

Further digging has revealed the true issue lies with the approach used to perform the HTTP Request and NOT the Graph Rest API!

Spoiler Alert: don’t use MSXML2.XMLHTTP60 for your HTTPRequests!

Up until now, I have been using MSXML2.XMLHTTP60, but a quick test switching over to using MSXML2.ServerXMLHTTP60 or WinHttp.WinHttpRequest.5.1 (with a “Cache-Control”, “max-age=0”) and the problem is resolved.

So there is some type underlying of caching issue when using MSXML2.XMLHTTP60 and thus it should be avoided. Even adding the “Cache-Control”, “max-age=0” directive does not work to remedy the issue. It would seem that MSXML2.XMLHTTP60 does not respect caching header directives.

I’m not sure why the workaround mentioned above manages to resolve the issue when using the MSXML2.XMLHTTP60, but you are best to simply switch approaches to avoid the issue altogether.