Integrating with Microsoft Graph API – Creating a Calendar Event

Reading time: 4 minutes

Microsoft Graph API allows developers to access data and services across a wide range of Microsoft cloud services. Admittedly setting up permissions and security can be challenging, but once that is sorted, you will be able to access Microsoft services such as Office365, Outlook and Azure.  

Calling the Graph API with Linx allows you to efficiently automate tasks, or integrate with Microsoft products to ensure that functionality and data is accessible by your other systems.  

This post will specifically look at how the users and calendar functionality can be accessed through the graph API by using Linx.  

Getting Started  

We have built an example solution that illustrates how to interact with the Microsoft Graph API. You must provide your Tenant ID, Client ID and Client Secret. These are all available on your Azure dashboard. Ensure that the correct permissions are applied. You can see what permissions are required on the Microsoft Documentation. 

Once you have access, it becomes a simple matter of calling the correct endpoints.  

Authentication 

Microsoft Graph uses OAuth2 as one of its authentication options, we decided to go with this option in our sample. You will need to provide the following details: 

  • Tenant ID 
  • Client ID 
  • Client Secret 
  • Scope: Depending on what service you call the scope will differ, for working with calendars you will need to use https://graph.microsoft.com/.default 

If you are using the sample, it’s a simple matter of passing in those parameters into the GetToken function, the function will call the endpoint and it will return an Access Token for you to use in all other API calls.  

Creating a new Calendar Event 

The calendars endpoint focuses on calendar-related operations. It allows you to work with calendars associated with user accounts. You will need a few things to access a calendar: 

  • User ID: This is the user ID of the user who’s calendar you want to access. This can be retrieved by getting a list of all users.  
  • Callendar ID: The specific ID of the calendar of the user you want to access. This can be retrieved by listing the calendars for a specific user. 

Once you have the above, it’s a matter of building up the correct URI (the UserID and Callendar ID forms part of the URI) and then via a POST, you can create a new event. The request body can be seen on the official API documentation.  

The URI will thus look something like this: 

https://graph.microsoft.com/v1.0/users/{UserID}/calendars/{CallendarID}/events 

This URI can be dynamically created by using the Linx expression editor, where you can pass in parameters, format a string in a specific way and apply transformations as they are required.  

You need to pass in the event details in the request body, that in Linx will look something like this: 

Create Calendar event with Microsoft Graph API

The below screenshot shows the response received when the event was created.  

Create calendar event with Microsoft Graph API

The sample solution contains functions to: 

  • Do authentication and return an authentication token 
  • List all users 
  • Get a specific user via User ID 
  • List all calendars for a specific user ID 
  • List all events for a specific calendar 
  • Create a new event on a specific calendar 

Feel free to download the sample solution if you want to try this out yourself.        

Sign up to our Newsletter