smotti
smotti

Reputation: 233

users?$expand=drive fails with InternalServerError

We want to be able to include the information about each individual user's personal site (OneDrive for Business) within a collection, to avoid inefficient subsequent requests to Microsoft Graph.

Microsoft Graph API doesn't allow to query for the mySite field when getting a user collection via /users?$select=id,mail,mySite. This fact is documented in the Graph API docs. Thus we were looking for an alternative, and came across:

GET /users?$expand=drive

or

GET /users?$expand=drives

because drive corresponds to the user's personal drive and has the field webUrl which is the same as mySite.

But the requests result in the following error:

{
    "error": {
        "code": "InternalServerError",
        "message": "Value cannot be null. Parameter name: source",
        "innerError": {
            "request-id": "15d69169-937a-4525-a904-e4107704d8f1",
            "date": "2017-11-08T02:11:17"
        }
    }
}

This is a valid documented relationship. Also nowhere is it documented that this use of the $expand query parameter is not supported. Though there is a note here that says $expand is for now only supported by the beta/users, but this still fails with the same error.

A potential cause of the error could be that the user hasn't created a personal site yet, thus we tried drives (as stated above) assuming it might just return an empty list and also the following:

GET /users?$expand=drive&$filter=drive ne null

But this also returns an error, stating that Filter is not supported. Though that $filter can't be used like that is not documented. Only that $expand=drive($select=webUrl;$filter=webUrl ne null) is not supported as documented here (if we understand that correctly).

We searched the office feature suggestion platform, Stack Overflow, and the Microsoft's tech community developer group, without success.

There is still the discovery API but this is not really an option because we use an app-only token. Furthermore does it look like that Microsoft Graph is also supposed to replace it, as mentioned here.

Upvotes: 2

Views: 637

Answers (1)

Marc LaFleur
Marc LaFleur

Reputation: 33124

Expanding a drive from a user entity isn't supported by Microsoft Graph. As to why, I will attempt to explain.

To understand this behavior, it's imported to consider where a given entity is sourced from. In this case the user comes from Active Directory while the drive is sources from SharePoint.

As noted in the documentation:

Note: Not all relationships and resources support the $expand query parameter. For example, you can expand the directReports, manager, and memberOf relationships on a user, but you cannot expand its events, messages, or photo relationships.

Using just the example, notices that directReports, manager, and memberOf are all sourced from AD while events, messages, or photo are all source from Exchange.

What the documentation is attempting to explain (albeit in a rather confusing and round-about way) is that $expand can't cross service boundaries. If the relationship crosses from one service to another (i.e. Exchange and SharePoint), Microsoft Graph isn't able to navigate across that boundary in a single call.

Part of this stems from the various services surfaced through Microsoft Graph having different rules and constraints. For example, Exchange has different rules around throttling than OneNote. Crossing between services via $expand would present problems when it comes to resolving which rules to apply.

Hope this helps.

Upvotes: 1

Related Questions