Application Development with Microsoft Graph
A lot of companies are already using cloud based solutions, among others because of the speed and flexibility of cloud platforms in providing solutions and the long term lower costs compared to On Premise solutions.
Microsoft offers a fast growing platform with Office 365 and SharePoint, which is used by a lot of companies and organizations all over the world. Office Graph offers an access point to a lot of interfaces for Office 365, in the future for SharePoint On Premise for hybrid SharePoint environments, also. This blog post tries to give a basic understanding of Office Graph and the Microsoft Graph API. It gives insight on how to use the Microsoft Graph API based on a sample Universal Windows App. Office Graph and the Microsoft Graph API in my opinion offer a lot of possibilities for partners and developers to build solutions and addins, that are consuming the interfaces offered by the API. That gives us a great chance to provide a greater user experience to our customers.
Office Graph Overview
What is Office Graph?
First I think it’s necessary to understand what Office Graph and Delve stands for. Delve was developed as an application based on the Microsoft Graph and it’s now used in the Next Generation portals. Delve presents information and content from Office 365 to the user like documents, people, tasks etc., which could be interesting for the user. It collects this information form everywhere in the user’s tenant. Delve is the application that does the presentation of the information to the user, Office Graph holds the intelligence that delivers this information.
Office Graph exists inside Office 365 and saves information about entities and their relationships. This information is stored as so called edges and nodes in the Office Graph Index.
So the office graph holds a lot of information about objects, for example people, documents, tasks and emails. I will list some examples here about edges and their possible relationships:
Modified: A user has modified a document.
Viewed: A user viewed a document.
TrendingAorund: Items that are used by the user’s colleagues.
OrgColleague: colleagues that work in areas that could be interesting for the user.
In the following chart you can find a lot of entities and possible relationships that are used by Office Graph.
Office Graph uses Machine Learning technology to build connections between objects and as well it’s using machine learning technology to analyze objects and their relationships existing in the Office 365 platform.
Microsoft Graph API
With Microsoft Graph API Microsoft provides a single point of access to various Microsoft cloud services through REST API.
Microsoft Graph API offers developers access to aggregated data of different services. They can access objects and relationships through the API, which are offered by the API and which were analyzed with Machine Learning technology.
With the help of Microsoft Graph API its now easier to find data from multiple sources and to use the intelligence of Microsoft cloud services. It makes it as well easier for developers to offer solutions based on these services, as well. Microsoft Graph API is accessible through the REST API endpoint „https://graph.microsoft.com“
In the following table you can find examples of service endpoints, that are offered by Microsoft Graph API[1]:
The structure of the Microsoft Graph developer stack
To be able to develop applications based on the Graph, there should be a basic understanding of the Graph’s developer stack. It can be explained with its four layers. The first layer is the data layer. You can find Office Graph and Microsoft Graph in that layer and here they deliver information about people, documents, emails and notes and as well as information about their relationships with each other.
The next layer’s jobs are authorization and authentication. It uses OAuth 2.0 and OpenID Connect.
The third layer focuses on development. Here we can use different tools to develop our solution like Visual Studio, Xcode or simply REST calls and some other approaches as well. Microsoft offers different SDK’s for Windows. IOS and Android. For example you can find Graph SDK preview on GitHub[1].
The fourth layer is the layer where you deploy your app or solution. We can use the azure platform together with windows, IOS or Android solutions or other hosting possibilities. So you are able to develop solutions for the most common platforms. In the following graphic you can see the architecture of the stack[1]:
How can you test Microsoft Graph queries?
There is a very simple offering to test your queries in your browser. You can use the Graph Explorer, which you can find with the following URL: https://graph.microsoft.io/de-de/graph-explorer.
To be able to do a test query, you must connect with your Office 365 identity. Then you are able to do queries on your Office 365 Tenant. First time you try that, you have to provide access rights for the API explorer to be able to work with your tenant, see screenshot below.
An example call could be „https://graph.microsoft.com/v1.0/me/ “. This returns information about your own profile. In the next listing you can find the result, which is shown in your browser:
That’s a simple way to test your Graph queries in the browser and to get an instant result.
Develop a Windows Universal App consuming the graph
Microsoft has some examples and SDKs for development with Microsoft Graph available for download[1]. Subsequent we are shortly talking about how it basically works to develop a Windows Universal app that can consume data from the Graph. To be able to develop an app with the Graph, you have to fulfill following requirements:
Visual Studio 2015
A Windows 10 environment that has developer mode enabled
an account connected to business Office 365 subscription
it’s required as well to have a Microsoft Azure Tenant, where you can register your app.
You need an Azure tenant also, where you can register your application. It’s necessary that this azure subscription is connected to your Office 365 tenant.
As soon as we have met all the prerequisites, we can start developing a Universal Windows App. As a first step you have to register that app in your azure environment, so it’s authorized for the necessary activities.
To register that app, you have to add the application to the previously registered Office 365 Directory. While registering, among others you have to register a Redirect URI. In the following screenshot of a form you can register the Client-Id as well, that should be used by your app.
The screenshot was done in a German environment; the Redirect-URI should be located in the field “UMLEITUNGS-URI”. In the next step you have to grant access rights to the application, to be able to use the Graph. You can for example use the following access rights for Office Graph:
View user’s profile
Read items in all site collections
Read all groups
etc.
You should grant the necessary and maximum needed access rights here.
In the App.xaml configuration file of your Windows 10 Universal app you have to configure the Client-ID and some other parameters, shown in the next listing.
Now it’s possible to for the app to authenticate on the tenant, by additionally asking for the user’s credentials. Now as we finished preparations, you can go on with developing and designing your app, you can fulfill different requirements with your app, for example query the Graph for needed information, up- and download documents to Office 365, work with tasks etc. So I think we can imagine a lot of things that we can do with the Graph now.
For this blog post I decided to develop a very simple Windows Universal App, which should show us my personal last modified documents. It should be possible as well to open the documents from the app and to be able to work with them as we are used to. The app queries the graph with “https://graph.microsoft.com/v1.0/me/drive/root/children/me/drive/root/children“ additionally filtered by the terms “Office” and “Hybrid”. In the following screenshot you can see the result, emulated in a Windows 10 device.
Conclusion
The Graph offers us a lot of options and the machine learning technology will provide us a lot of fascinating possibilities in the future to create new solutions and develop new ideas to satisfy our users with better and faster information. From a developer’s point of view Microsoft already offers a lot of things provided with the SDKs and in my opinion they will improve in the near future, so we are able to offer outstanding solutions.
Jürgen Schmailzl works as a Solution Architect for the German based Fritz & Macziol. He has over 10 years’ professional experience in SharePoint, BI and .Net area. He consults customers in the area of collaboration, Azure, Office 365 and mobile development. He is frequently writing articles. You can find an article about Microsoft Graph as well in the German magazine Windows Developer, edition 8.16 coming up in July.
Links & and additional literature
[1] Ignite highlights – Delve and the Office Graph https://blogs.technet.microsoft.com/msuspartner/2015/06/11/office-365-partner-community-ignite-highlights-delve-and-the-office-graph/
[2] Overview of Microsoft Graph
http://graph.microsoft.io/en-us/docs
About the Author
Jürgen Schmailzl is a Solution Architect at Fritz & Macziol and has more than ten years experience in SharePoint, BI and .NET environment operations.
Follow Jürgen on Twitter: @JSchmailzl