Microsoft Graph API – A SIngle Stop For Your Cloud Solution

Today I am writing about the “Microsoft Graph API – A Single Stop for your cloud solution” which I have presented in SPS Dubai event. Its a long time though !! 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 one-drive, outlook, office 365 Groups, Users and many more.

Well, in order to reach to 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!

Violet Step: Microsoft Graph Sneak Peek

Indigo Step: What is Microsoft Graph API?

Blue Step: Microsoft Graph Developer Stack

Green Step: Demo Using Microsoft Graph Explorer

Yellow Step: SDK and Tools details for Microsoft Graph API

Orange Step: Demo Using Visual Studio

Red Step: Benefits and References

Once you understand this colorful steps, you are good 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 has announced the amount of data and its usability by people within the Office 365.

Over 200 million downloads of Office mobile (WXP, Outlook, and OneNote on iOS and Android mobile devices).

More than 18 million consumer Office 365 subscribers.

60 million commercial Office 365 monthly active users.

More than half a billion people managing their documents and photos in OneDrive.

So, based on this statistics, you can imagine that 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?

Previously known as Office 365 unified API.

Exposes multiple APIs from Microsoft cloud services through a single REST API endpoint.

Seamless navigation between entities and the relationships among them.

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 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 MOST valuable and most COMPLETE solution for the enterprises.

And being with such technologies we as user 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 user need.

For example –

Whom I work closely with?

What documents and topics are important to my colleagues right now?

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 its 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 does and remove 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:

Content to manage

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.

Though connecting people and content and providing the most important result is a paramount to work fast and effectively and have better decision. In order to achieve this goal, Office Graph is introduced that connects 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 user is direct reporting to the 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.

So you see this is how 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.

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 do not require 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 center, Microsoft has opened new productive ways by

Enabling developers to quickly build the solution.

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:

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!

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 have now 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.

Ultimately, The Microsoft Graph gives you:

A unified API endpoint for accessing aggregated data from multiple Microsoft cloud services in a single response

Seamless navigation between entities and the relationships among them

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!

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:

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

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.

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.

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.

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 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.

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 :

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.

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 !

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:

Dipti Chhatrapati

Dipti Chhatrapati is a SharePoint specialist currently working as a Senior Consultant for CapGemini in Mumbai, India. She has more than 9 years of experience in application development, design, maintenance, administration and is continuously working with improving her skills and keeping them up to date. As a developer, project leader and SharePoint Business Analyst, she has been an extensive user of Visual Studio and Team Foundation Server throughout her career. Dipti is very passionate about music, sports, and arts and loves to spend her free time learning new things, socializing with friends and family, cooking, exercising and singing.

Dipti, thanks for writing such a detailed article and sharing with the community. I have few questions.

1. How does the registered App link to Office 365? Is assumption such that if you create an app with your office 365 admin credentials, it will automatically have access in querying Office 365 resources using the created app?
2. If we create an app, can we use the same app details (Client id, secret, access token) in a service layer(WCF service) to fetch Office 365 resources for multiple client based applications?

Hi Dipti Many thanks for your contribution in to MS Office Graph. A very comprehensive explanation. The bit I’m confused with is the bulkiness of it all – I downloaded the samples but they come with some serious chunks of other stuff. Previously, using REST API in JavaScript, you were able to do a quick call and return the response for manipulation quite rapidly. I haven’t seen a simple demo of that anywhere. I want to be able to display OneDrive files in a SP page – but not getting anywhere using Graph – any ideas, suggestions? SIMPLE REST API… Read more »

Hi Dipti, Can you please tell me about graph api link to know about already shared documents and file with or with out organization how we would know using Graph Explorer get api can you provide that link?

Thanks

Jaykishan Vaghela

Vote Up0Vote Down Reply

11 months 9 hours ago

Dipti Chhatrapati

SharePoint Enthusiast and Ambitious consultant with experience in all aspects of software life cycles, including Analysis, Design, Development, Testing and Support, functioning in various roles like Business Analyst,Solution Architect,Technical Lead and Developer.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.

AbuonMicrosoft Graph API – A SIngle Stop For Your Cloud SolutionHi Dipti Many thanks for your contribution in to MS Office Graph. A very comprehensive explanation. The bit I'm confused with is the bulkiness of it all - I downloaded the samples but they come with some serious chunks of other stuff. Previously, using REST API in JavaScript, you were able to do a quick call and return the response for manipulation quite rapidly. I haven't seen a simple demo of that anywhere. I want to be able to display OneDrive files in a SP page - but not getting anywhere usi…