What is the Microsoft Graph API?
The Microsoft Graph API allows a developer to access and process data from the various Microsoft cloud services, being Azure Active Directory, SharePoint, OneDrive, OneNote, Exchange Online and Planner.
All of this is possible from one REST endpoint that can be accessed from https://graph.microsoft.com. The technology that is used to call this endpoint is up to the developer, this allows for great flexibility.
You no longer need to get separate access tokens to connect to the various services, just one endpoint and one access token to access all the data within the Microsoft cloud services.
The endpoint
There are currently two endpoints that can be used, V1.0 is the current stable build and should be the one u use in a production environment. The beta endpoint contains new features but is subject to changes.
Authentication of your app can be done with the Azure AD V1.0 authentication endpoint, this allowes for users to be authenticated with Enterprise accounts. The Azure AD V2.0 authentication endpoint can authenticate both enterprise and personal Microsoft accounts. Note that V2.0 is still in active development and has some restrictions as described here. For now, Microsoft recommends the use of the V1.0 endpoint as is provides a richer feature base, unless you want to make use of personal accounts.
You can drill down to the content you need by appending the right methods.
An example GET request:
graph.microsoft.com/v1.0/me/drives/b!-WyshAvExkOx0xrf5HyJ0uDEB7w38qJHkHhqrevVvwvfKls-KuH-Rr417GQdrJhp/root/children/Slogan Suggestions.docx
graph.microsoft.com/v1.0/me | access to your graph data |
/drives | access to your onedrive |
/b!-WyshAvExkOx0…drJhp | id of a specific drive |
/root | the root folder of a drive |
/Children | all files and folders located within the root folder |
/Slogan Suggestions.docx | the specific file you like to access |
This returns the properties of the document in the following response:
{ "@odata.context":"url","@microsoft.graph.downloadUrl":"downloadUrl","createdBy":{ "user":{ "id":"b63d5fb9-4f43-44c4-8f9d-fd0727842876","displayName":"Alex Darrow"}},"createdDateTime":"2014-10-16T07:24:57Z","eTag":"\"{E44EFB11-32D1-4DAE-8734-8E988F0D78F7},1\"","id":"01CNPZDUYR7NHOJUJSVZGYONEOTCHQ26HX","lastModifiedBy":{ "user":{ "id":"b63d5fb9-4f43-44c4-8f9d-fd0727842876","displayName":"Alex Darrow"}},"lastModifiedDateTime":"2014-10-16T07:24:57Z","name":"Slogan Suggestions.docx","webUrl":"https://document url","cTag":"\"c:{E44EFB11-32D1-4DAE-8734-8E988F0D78F7},5\"","file":{ },"parentReference":{ "driveId":"b!-WyshAvExkOx0xrf5HyJ0uDEB7w38qJHkHhqrevVvwvfKls-KuH-Rr417GQdrJhp","id":"01CNPZDU56Y2GOVW7725BZO354PWSELRRZ","path":"/drives/b!-WyshAvExkOx0xrf5HyJ0uDEB7w38qJHkHhqrevVvwvfKls-KuH-Rr417GQdrJhp/root:"},"size":20020}
You can access and modify data throughout the Microsoft cloud services in a similar way, it is even possible to access the content of files. Getting the worksheets of an excel file:
graph.microsoft.com/{version}/me/drive/items/{id}/workbook/
Limitations
For now, there are some limitations when using the Graph API to access data within SharePoint. The following actions can be done with the beta version of the Graph API but are subject to changes.
- Sites
- Get the default site, get all sites, get specific site by ID, get specific site by url.
- Lists
- Get all the lists under a site, get a specific list by ID, get specific list by url.
- Libraries
- Get all the document libraries (called drives in the Graph API) under a site.
- Items and files
- Get a specific item by id, Get a specific file by url, CRUD actions on items and files.
There are still some common actions missing like Create, Update or Delete Sites, Subsites and Lists. These actions are not available in the beta endpoint and there is no date yet as to when these will be released, but at the European SharePoint Conference a few weeks ago, they told us that it’s definitely on the roadmap!
Conclusion
The Microsoft Graph API makes is easier to access data from all the Microsoft cloud services with just one access token and one endpoint. This will significantly improve development time! You should keep in mind though that the API is still in development, especially when it comes to getting and manipulating SharePoint data. This will eventually be possible in a future endpoint, but we still need to have a little patience.