OneDrive API Endpoint Differences

OneDrive API is available from several different API endpoints. Microsoft Graph is the preferred endpoint for accessing OneDrive personal, OneDrive for Business, and SharePoint online files. In some enterprise scenarios, like SharePoint Server 2016, it may be necessary to access OneDrive for Business and SharePoint data by using the direct API endpoint without using Microsoft Graph. The following notes provide details about differences you may notice between Microsoft Graph and the direct API endpoint.

Differences:

Namespaces

Methods

When using the direct endpoint, methods and actions require a namespace prefix. For example, to use sharedWithMe on the direct endpoint, you must prefix the action name with oneDrive.. Note, this prefix is case-sensative.

https://{server}/_api/v2.0/drive/oneDrive.sharedWithMe

The following actions or methods must be prefixed on the direct endpoint:

Instance annotations

Properties on items returned with an at-sign (@) also include a namespace. When using Microsoft Graph, the namespace is always microsoft.graph. However, when accessing the direct API endpoint, the namespace is different.

Documented Property Name Direct API Endpoint Name
@microsoft.graph.downloadUrl @content.downloadUrl
@microsoft.graph.sourceUrl @content.sourceUrl
@microsoft.graph.conflictBehavior @name.conflictBehavior

Discovering an endpoint

Microsoft Graph provides a single API endpoint, https://graph.microsoft.com for consumer and work/school accounts. Microsoft Graph is the preferred API endpoint for OneDrive and OneDrive for Business API access. However, if you need to continue using the direct API endpoint for OneDrive or OneDrive for Business due to existing code, you can discover the correct OneDrive API endpoint using Microsoft Graph.

OneDrive personal accounts

When not using Microsoft Graph, the API end point for OneDrive personal is always the same: https://api.onedrive.com/v1.0. OneDrive personal does not require any end point discovery.

You can determine if the signed in user is a OneDrive personal user by checking the id_token for tid: 9188040d-6c67-4c5b-b112-36a304b66dad. More information about this is available on the Active Directory v2 protocol topic.

OneDrive for Business and SharePoint

When not using Microsoft Graph to access OneDrive for Business, your app must first discover the user's My Site URL. You can make a request to Microsoft Graph to return this information:

GET https://graph.microsoft.com/v1.0/me?$select=mySite
HTTP/1.1 200 OK
Content-Type: application/json

{
    "mySite": "https://contoso-my.sharepoint.com/personal/rgregg_contoso_com/"
}

You can then append the API path for the OneDrive API, _api/v2.0/ to this URL, to construct the API endpoint:

var apiEndPoint = response.mySite + '_api/v2.0';

In some cases a work/school user may not have a mySite value returned. This occurs when the account has not created their OneDrive for Business yet. In this scenario, your app will need to use Microsoft Graph to provision the user's OneDrive by requesting the root folder of the drive from Microsoft Graph.