Microsoft Graph API – A Single stop for your Cloud Solution.

The purpose of this article is to help you to build a Cloud App using Microsoft Graph API as per your business requirement that works with data from different cloud services whether it’s a OneDrive, Outlook, Office 365 Groups, Users and many more.

Well, in order to achieve our final goal, we have to climb the 7 steps which I have categorized by seven rainbow colors to understand how Microsoft Graph API is a single stop for your cloud solution! Let’s see what it gets for you!

  1. Violet Step: Microsoft Graph Sneak Peek
  2. Indigo Step: What is Microsoft Graph API?
  3. Blue Step: Microsoft Graph Developer Stack
  4. Green Step: Demo Using Microsoft Graph Explorer
  5. Yellow Step: SDK and Tools details for Microsoft Graph API
  6. Orange Step: Demo Using Visual Studio
  7. Red Step: Benefits and References

Once you understand these colorful steps, you are ready to crack the development projects using Microsoft Graph API!

Violet Step: Microsoft Graph Sneak Peek

Before we go in deep, I want to tell you that two months back, Office Extensibility team from Microsoft had announced the amount of data and its usability by people within the Office 365.

  1. Over 200 million downloads of Office mobile (WXP, Outlook, and OneNote on iOS and Android mobile devices).
  2. More than 18 million consumer Office 365 subscribers.
  3. 60 million commercial Office 365 monthly active users.
  4. More than half a billion people managing their documents and photos in OneDrive.

So, based on this statistics, you can imagine how rich and heavy data is flowing within the Microsoft cloud services via people because we have started working in a network and connect the information using various cloud services.

What is Microsoft Graph then?

  1. Previously known as Office 365 unified API.
  2. Exposes multiple APIs from Microsoft cloud services through a single REST API endpoint.
  3. Seamless navigation between entities and the relationships among them.
  4. Access entities like users, groups, mail, messages, calendars, tasks, and notes coming from services as well as the relationship from the office graph.

If this is the case then what is Office Graph what we hear here and there ? ( For your information, Facebook is also using Graph API, whenever its a network – Its the only Graph database that can maintain your data )

Well, as you all are aware about that now a days, Office 365 provides simpler and centralized IT management that has improved communication and reduced IT administration of enterprises all over the world. As people are being more focused and data is being more centralized, O365 is considerably the MOST valuable and the most COMPLETE solution for enterprises.

And being with such technologies we as used to getting data congestion in everyday life with new information via emails, calendar events, documents, social feeds and hence we get confused to identify the relevant information which is only important and because of that its being hard to make the quick decision because it consumes more time in finding the information that the user needs.

For example –

  1. Whom I work closely with?
  2. What documents and topics are important to my colleagues right now?
  3. What matters the most to my boss?

And in order to resolve such scenario, Office Graph has made the job easy to find what you need as it is providing an intelligent fabric that presents the bunch of content and activity and the relationship between them across entire O365 cloud services whether its email, conversations, documents – Office Graph uses machine learning algorithms to connect people with relevant information and actions occurring around them.

For example, the clutter in Outlook that uses the same intelligence as office graph removes the irrelevant information from the inbox and provides most important emails first .Basically office graph learns and understand our daily activity through machine learning algorithm.

Today, we are working with many cloud services, like OneDrive to manage documents, outlook for emails, Calendar to create events, groups for collaboration and yammer/skype for the conversations. Actually all this services are mainly focused on two parameter:

  1. Content to manage
  2. People to have conversations

Both are using different silos in office 365 and we keep using them for our individual task within a team/organization.

Microsoft Graph API

Though connecting people and content and providing the most important result is a paramount to work fast and effectively and have make better decisions. In order to achieve this goal, Office Graph is introduced to connect each tools by linking the entities together. In other words, office Graph contains nodes and relationship between the nodes. Moreover, Office Graph will be having its own endpoints to interact with Active Directory  and hence Office Graph is in real term a brain for O365.Now, let’s see how machine algorithm learns our daily activity in a next slide.

So here in this diagram, you will see the user is direct reporting to another user, then linked to yammer for the conversation, also working with the colleague, then view the documents which is trending around the user, then email which has been shared with the user also who is manager for this user and which slide has been presented by user and so on it gradually increased by linking other tools, content and people.

Microsoft Graph API Map

So you see this is what the Office Graph looks like, simply kind of Spider Net but I would assume as Microsoft Office Net!

Anyways In other words, as soon as we work with more documents and people, machine learning algorithms understand and store the frequent actions and relation with the users and documents overtime. Basically, office graph contains nodes like document/user and relationship between nodes like to whom user reports, with whom user works with, which document has been viewed by user and so on.

This is how office graph provides personalized experience to user. One more thing – Microsoft Graph is not only about the one user but it’s about the entire organization as people are interconnected via different actions and entities using cloud services in office 365 and hence this is an absolutely powerful feature in office 365.

And this is all about the basics of Microsoft graph and Office Graph!

Indigo Step: What is Microsoft Graph API?

Now, let’s move to our second Indigo step and that’s a Microsoft Graph API! So far we have discussed about Microsoft Graph and Office Graph, but this is a Microsoft Graph API, Don’t Panic! 🙂 between Graph terms , it’s a damn simple – Microsoft Graph API used to access O365 cloud services as well as Office Graph and hopefully it’s now understandable!

The Office Graph computes insights across Office 365 and makes these insights available through the Microsoft Graph API, the single endpoint that you can use to access a number of Microsoft’s cloud services.

Actually Microsoft Graph API is a recent term used to rename O365 Unified API that exposes multiple APIs from Microsoft Cloud services through Single REST API End Point.

Microsoft Graph API - REST

1. Data Silos :As you see in the diagram, O365 data is scattered in different silos such as users, groups, files, Mails, Calendars, Contacts, Tasks, People, Excel and Insights and Relationships from Office Graph

Earlier, it was very challenging for the developers to access all these data because for each different silos there were different API to connect with data.

For example, to access users, people and groups it was possible by Azure Active Directory Graph API, then to access the SharePoint user properties then there has to access the SharePoint user profile api and to access the user’s picture then there was exchange endpoint.

In addition, to access mail, conversation and events there was Exchange Rest API and to access files there was one drive for business or SharePoint Files API

2. Microsoft Graph API :So you see, it was very difficult for developer to access different API for different types of data, but now Microsoft Graph API is to rule them all. In short, Microsoft Graph API accesses Office Graph data via single end point which is https://graph.microsoft.com to display office data in your cloud app.

Moreover, Microsoft Graph API require single access token which was previously different in O365 API – Meaning you are not required to create separate access token to access data from different data silos.

3. Your Cloud App: Using the Microsoft Graph, you can have difficult or complex queries into simple navigation. Also by keeping the developer experience at the center, Microsoft has opened new productive ways by

  1. Enabling developers to quickly build the solution.
  2. Empowering the enterprises to customize and extend the O365 experience.

The bottom line is: The Microsoft Graph gives you A unified API endpoint for accessing aggregated data from multiple Microsoft cloud services in a single response using a single authentication token and Seamless navigation between entities like users, groups, mail, messages, calendars, tasks, and notes coming from services like Outlook, OneDrive, Azure Active Directory, Planner, OneNote and others as well as the relationships among them by Office Graph.

You know What I consider MS Graph as:

Image 4

And I believe, you would have understood reason behind it and if not then you will get to know in the coming steps 🙂

Blue Step: Microsoft Graph Developer Stack

Now the 3rd BLUE step has information about Microsoft Graph Developer Stack!

Image 5

Here we will understand high level architecture for developing a solution using Microsoft Graph API.

At first place Microsoft Graph API endpoint accessing the insights and relationships from Office Graph. This is the same as we just saw in previous slide as 2nd step.

Also, In order to connect the Microsoft Graph API, we require single access token that’s authenticated and authorized by Open ID connect and Oauth 2.0. Protocols respectively.OpenID connect is an identity layer on top of Oauth 2.0 that authenticates the user like who is that user It asks to user for example an email id in order to know the identification of the user and Oauth protocol actually provides authorization to user and gives an access token from an authentication provider for example Office 365 and this access token later used to access a Microsoft Graph API!

Then, on top of it there will be development environment as per your choice whether its Android/Asp .NET/IOS/Node/PHP/Ruby/Angular etc., you see much freedom over development platforms  on which you will build up your cloud APP Solution – AS SIMPLE AS THAT !! ? Having fun till now? 🙂

Green Step: Demo Using Microsoft Graph Explorer

Going forward, we now have the  4th Green step about DEMO by Graph Explorer.

Here, we will see the demo to query data using Microsoft Graph API for different entities like users, groups, mail, messages, calendars, tasks etc.

You can try getting your data in json format via different Microsoft GRaph API endpoints on following link.Do not forget to get login first !

https://graphexplorer2.azurewebsites.net/

Following screen says kind of information we can access using graph explorer.

Image 6

Ultimately, The Microsoft Graph gives you:

  1. A unified API endpoint for accessing aggregated data from multiple Microsoft cloud services in a single response
  2. Seamless navigation between entities and the relationships among them
  3. Access to intelligence and insights coming from the Microsoft cloud

In general , you access and manipulate data for user profile from AD or SharePoint, Files from one drive , Photo ,emails,calendar events, manager, details, last modified user of particular file,groups,user,conversations,people who are related to me, People with whom I am working,tasks,notes and files which are trending around the user.

So lots of useful data you can get using single endpoint!

Image 8

However, Microsoft graph is currently in preview stage and having two endpoint versions available:

https://graph.microsoft.com/beta/ – that’s used to explore the features which are not ready for production app.For example – Tasks,People,Excel,Notes,Organization Contacts and Office Graph.

And https://graph.microsoft.com/v1.0 – That’s absolutely available to use for your production environment.For example – Users,Groups,Files,Mails,Calendars and Contacts.

Now, In order to request cloud data, MS Graph API has certain syntax so the request pattern goes like this way:

  1. {Graph Endpoint} https://graph.microsoft.com is the Microsoft Graph API endpoint
  2. {Version} is the target service version, for example, v1.0 or beta.
  3. {Tenants} which is optional and not required with Entity set where you can specify your tenant name and its specific entities like users,groups,files etc. !
  4. {Id} is used to mention the particular item from the entity set for example, single user, and file.
  5. {Property} through which you can access the specific property of the particular object selected from the entity set.

Also there are optional parameters which you can use to control the amount of data like:

Select to have specific properties of an object in response: https://graph.microsoft.com/v1.0/me/messages?$select=from,subject

Expand to view the children collection to For example, to retrieve the root drive information and the top level items in a drive

https://graph.microsoft.com/v1.0/me/drive/root?$expand=children($select=id,name)

Order By to use to sort the resulted items in ascending or descending order. https://graph.microsoft.com/v1.0/users?$orderBy=displayName%20desc (asc )

Filter to fetch the data based on certain criteria https://graph.microsoft.com/v1.0/users/?$filter=surname eq ‘Chhatrapati’ https://graph.microsoft.com/v1.0/users?$filter=startswith(givenName,’Dipti’) Top to get specific number of resulted items

https://graph.microsoft.com/v1.0/users?$top=3 https://graph.microsoft.com/v1.0/me/messages?$top=5

Skip For example, to return events sorted by date created, and starting with the 21st event, the syntax is as follows.

https://graph.microsoft.com/v1.0/me/events?$orderby=createdDateTime&$skip=3

There is also a $skip Token to page and specify the next set of results to return and $Count to return the number of resulted items.

Getting my profile gives you not only the azure active directory properties, but properties that are part of SharePoint or Exchange, Unfortunately AD users are not integrated in my tenant and hence we see only available properties.

What Microsoft Graph API has done here? It has made all the entities together and made the easy access on all the O365 cloud data.

Yellow Step: SDK and Tools details for Microsoft Graph API

As we have already discussed that this API is available for multiple development environment like windows, iOS, android, node, php, python, ruby on rails, asp.net mvc and angular JS web apps.

Image 9

Not only this, but GitHub is having all the sample available to get you started with your apps for example sending an email, manages groups and active directory etc.

At the moment SDKs are available only for mobile devices like IOS and Android while others are yet to be released by Microsoft.

Orange Step: Demo Using Visual Studio

Going forward, we have now 6th Orange Step and here I will present a simple demo using asp.net MVC application to create a cloud solution using Visual Studio. Here, we will cover what is require to build a cloud app that works with Micro soft Graph API.

Image 10

There are three basic steps:

1. Choose your development environment – http://dev.office.com/gettingstarted/office365apis. Using this link , you can choose environment and download the solution by registering the app in Azure AD.

2. Register an App in Azure AD – https://dev.office.com/app-registration. Using this link you can explicitly register your cloud app in Azure Active Directory as it will open up avenues to access the data from Office 365.

Remember – Azure AD subscription must be associated with your Office 365 business account.

The Sign-on URL is the address of a web page where users can sign in and use your app. The value set for this property is also set as the value of the Reply URL. The App ID URI is a unique identifier for Azure AD to identify your app. It must be a unique value in your organization’s Azure AD.

The client ID is used to identify your app when it connects to Office 365. The client secret acts like a password for your app.

You can now use these values in your code to get your app connected and accessing

3. Configure Permission Scope – https://manage.windowsazure.com

By registering the app in Azure AD, you can also configure the permission scope using Azure AD portal as well as via O365 registration tool in order to access data for different purpose.

For more details on permission scope, you can look on following link:

http://graph.microsoft.io/en-us/docs/authorization/permission_scopes

And, now you can start cracking the application as per your business requirement. Now you have an app solution ready which is registered in Azure AD so let’s see, how this app works so that you can customize further as per your requirement.

Image 11

This APP actually send an email to specified user ID using Microsoft Graph API and As we discussed earlier, MS Graph API require a single access token to access office data and hence this solution also has to implement 3 basic steps :

  1. Authenticate User with O365 – The Azure AD Authentication Library (ADAL) for .NET enables client application developers to authenticate users, and then obtain access tokens to make API calls. You can include this library in your ASP.NET MVC project via Manage NuGet packages in Visual Studio.
  2. Get Access Token using ADAL – This will be done by calling method Authorize() which will get the access token in exchange of client id and secret Id that has been used to register the APP in Azure AD !
  3. Request MS Graph API using Access Token using GetUserInfoAsync() method and SendMessageAsync() to get the user information as well as to send an email to specified email id respectively.

So this is how you can get and post the data using MS Graph API through cloud app, in the same fashion you can implement other data and display in your app.You can also create following types of apps:

  • Managing Azure AD Users.
  • Managing projects and team
  • Creating Office Add ins/SharePoint Add In / O365 Add In.

Red Step: Benefits and References

Image 12

  • Consistent and streamlined developer experience for consuming Microsoft cloud services
  • Consistent property naming and schemes across entities, including navigation properties between entities
  • Enable developing apps in any programming language on any platform

Useful Links:

Description Link
Office Graph http://dev.office.com/officegraph
Office 365 Unified API (Preview ) https://dev.office.com/unifiedapis
Microsoft Graph Documentation http://graph.microsoft.io/docs/overview/overview
Microsoft Graph Explorer https://graphexplorer2.azurewebsites.net/
API Sandbox Preview https://apisandbox.msdn.microsoft.com/
Creating O365 App http://dev.office.com/getting-started/office365apis
Office 365 app registration tool https://dev.office.com/app-registration
Manually registering app in Azure AD http://bit.ly/20sbWH7
Change Log http://graph.microsoft.io/changelog
Ask Questions to Stack Overflow Tag your questions with [MicrosoftGraph] and [office365]
Ask Questions on Twitter Tag your questions with #MicrosoftGraph and #office365dev
Application demo developed by Microsoft Graph API http://bit.ly/1O6oX1V

 And now there is a surprise simple test “Give and Get “, Give the answer and get the knowledge 🙂

No.
1 What is the difference between Microsoft Graph API and Office 365 Unified API ?
2 What is the difference between v1.0 and beta version of Microsoft Graph API ?
3 Which are two ways to register cloud applications ?
4 Which SDKs are available to implement cloud solution using MS Graph API ?
5 How App permissions are considered to access data from O365 cloud service ?

Well, I think these were all 7 colorful steps and I hope you would have enjoyed being colorful during a walk through of this article and that’s all about it

Entire Slide is available here which I have presented during my session in SharePoint Saturday Dubai on 30th January 2016.

You can also customize the solution further, using following solutions which are available in GitHub !

ASP.NET MVC – https://github.com/OfficeDev?utf8=%E2%9C%93&query=o365-aspnetmvc-microsoft-graph

Angular JS – https://github.com/search?utf8=%E2%9C%93&q=O365-Angular-Microsoft-Graph-Connect

Happy Clouding!!

About the Author: Dipti ChhatrapatiDipti _chhatrapati

SharePoint enthusiast and Ambitious consultant with 6 years of experience in software development, design and administration. Working continuously to improve my skills and keep them up to date. Willing to accept roles and responsibility with challenging tasks in the SharePoint technologies.

Share this on...

Rate this Post:

Share: