The Microsoft Graph API allows access to Microsoft cloud resources such as Office365 and Enterprise Mobility and Security Services. In this article, Julio Sampaio demonstrates the Graph Explorer and builds an example that sends an email.

It is a common practice for big players in the cloud market to allow their users to have more than one method to access their data. With Google, for example, you can have one single account and easy access to a bunch of free services like Gmail and Drive.

Google also provides public APIs for developers to be able to access data via other applications. The whole process happens through the usual OAuth +, an application provided by the player.

With Microsoft, there’s Microsoft Graph. It provides some REST endpoints that allow access to their services like Office 365 (which is in the cloud, unlike the older versions), Azure and Outlook.

Here’s a single example for you to get a taste. A common URL endpoint to retrieve personal information about a specific account is https://graph.microsoft.com/v1.0/me. Here’s what you’ll get if you try it out in a browser tab:

{
  "error": {
    "code": "InvalidAuthenticationToken",
    "message": "Access token is empty.",
    "innerError": {
      "request-id": "a2115c87-341f-405a-b127-d3432748d38b",
      "date": "2020-06-08T13:46:07"
    }
  }
}

That’s when OAuth takes place. The URL, in turn, follows some pattern rules that you’ll see right away.

Microsoft Graph API Structure

The access to each resource must follow a pattern. Here’s the request construction:

{HTTP method}https//graph.microsoft.com/{version}/{resource}?{query-parameters}

First, as usual, you define the HTTP method for the operation. Note that it’s not up to you to decide that; you must go to the docs and check which method is available for that operation. Plus, the endpoints follow the RESTful principles, so make sure to refer to it for better comprehension.

Then it comes the version of the Graph API you’re targeting. As per the writing of this article, the only available versions are v1.0 and beta. As you may have noticed, for production purposes, only the v1.0 version should be used. The beta version brings some new stuff, which might include breaking changes, so be careful when using it.

The resource defines the entity (and its properties) you’re willing to access. These resources usually come alone like in the previous example (/me), so they’re called top-level entity resources. However, you may want additional inheriting data, like /me/messages, for example. You can refer to the list of available resources here.

Remember that each resource is secure information, so it requires permission to be accessed. You’ll see more about how to do it soon.

Finally, you have the parameters. Like the other REST API endpoints, it’s necessary to provide the filters for the endpoints that demand that, like when retrieving all of your email messages filtered by the sender, for example.

Microsoft Graph API makes use of the OData (Open Data Protocol) namespace, which defines a set of best practices for building and consuming RESTful APIs. You can read more detailed information about the whole API architecture here.

#.net development #cloud development #homepage #sql prompt #cloud

Getting Started with Microsoft Graph API
2.80 GEEK