Microsoft Graph – using Outlook Calendar API

Microsoft Graph - using Outlook Calendar API

I am sure you know Microsoft Outlook. You probably use it at home, at work or in college. It may happen that at your work exists an internal project management system and office assistants would like the meetings added there to be automatically joined to the calendar in Microsoft Outlook. Nothing easier! In this case, you can use the Calendar API available in Microsoft Graph. In this post, I will introduce you to this topic.

Microsoft Graph

Microsoft Graph is a platform that connects various services and devices. It is described as a gateway to data and intelligence in Microsoft 365. You can want to take some information from SharePoint, OneDrive or other devices from Microsoft 365. Microsoft Graph enables you this possibility. The graphic below illustrates this perfectly.

Microsoft Graph

Outlook Calendar API

Outlook Calendar is a part of the Outlook messaging hub. Of course, It is included in Microsoft 365. Thanks to that you can, for instance, manage your team meetings and find information about the availability of your colleagues. To exploit the potential of this tool in its internal system, you can use Outlook Calendar API. Now let me show you how to do this in C#.

Graph Explorer

Before writing code in C#, we will take a look at Graph Explorer. As the name suggests, we use it to check the possibilities offered by Microsoft Graph API, including our Outlook Calendar API. You should see the following window:

Graph Explorer

In the left section, you have some sample queries available. There are also those related to the Outlook Calendar we are interested in. To use this, you need to select the query you are interested in and just run it. You can also create your requests. It is a great tool for testing the capabilities offered by Microsoft Graph.

Graph Explorer - Sample queries

Using Outlook Calendar API in C#

So let’s start by creating a console application project. Then add the following libraries using NuGet Packages:

Using Outlook Calendar API in C#

Now the key element is to register our application using Microsoft Azure which is necessary for us to integrate with the Microsoft identity platform and call Microsoft Graph. So we enter the Azure portal and go to Azure Active Directory. Then select ‘App registration’ from the panel on the left and you can go to ‘New registration’:

App registrations in Microsoft Azure

Here you enter the name of the application and the type of account you are interested in. If you are not sure about it, I recommend choosing the option shown below:

Register an application in Microsoft Azure

After successful registration, you should be able to access the following view:

Overview in Microsfot Azure

The next step is to add the appropriate permissions to our application. So select the ‘Add permissions’ tab in the left panel. Select ‘Microsoft Graph’ and then the appropriate permission type. The next step is to find the ‘Calendar’ tab and select the options there. Finally, click on the ‘Add permissions’ button and you can go back to Visual Studio.

Request API permissions

Now we will move on to creating a GraphClient in our application and an Authentication provider. Later, you can send requests for downloading various data from your calendar or adding meetings. For this you need the code shown below:

The first lines of code are responsible for creating the Authentication provider. The first string you see there is the Application ID I mentioned earlier. The other one is the Tenant ID. In the next line, we see the creation of an instance of the Microsoft Graph client. Then it is already creating the event object and putting the necessary information there. Finally, the request is created, where the string is simply the User ID for which this meeting is to appear in the calendar. After you execute this method, the meeting will appear on your calendar. It is simple, right?


In this post, I wanted to show you how to start playing with Outlook Calendar API and introduce you to what efficiency it provides. Using it is really easy and you can quickly add some features to your application. Other useful examples you can find in the official documentation. I also encourage you to check out my other technical posts.

Leave a Reply

Your email address will not be published.

Scroll to top