Outlook and Microsoft Office are one of the most popular business software packages and services on the planet, with Outlook.com alone boasting over 400 million users in 2018. And with the Microsoft Graph API, integrating with Outlook and its calendar has never been easier. In this article we will walk through how to use the Microsoft Graph API to automatically create events in Outlook Calendar using FileMaker, streamlining event and scheduling management in your FileMaker solution by eliminating double data entry.
What You Need
You must have Office 365 to use this article’s integration, as the Microsoft Graph API does not support Outlook hosted on Exchange Server. Also make sure you have admin access to your Office 365 subscription if you have a business or school user account.
Creating a Microsoft Graph Application
Make sure you create Azure AD Tenant first if you are using a personal account and not work school account. Similar to other API integrations, you need to create an app first. Go to the application registration portal and add an app (Note: the video shows old application registration page. New process will have you start from Azure portal as of May 1st, 2019). Click New Registration, give it any name, and select account type depending on who will be connecting to this application.
Then click on Certificates & secrets tab and create new client secret. Don’t have expiration date unless there’s specific reason to do so.
Managing App Permissions
Microsoft Graph requires that each user give the app permissions to be able to push and pull data to and from their Outlook Calendar. Before users can give permissions, you need to set up the default permissions on the application registration page. There are two types of Microsoft Graph permissions: delegated permissions and application permissions. For purpose of this article, we will be using delegated permissions to talk to Outlook Calendar as a user instead of as an application.
For this Outlook Calendar Integration you will need to add the following delegated permissions:
- Calendars.ReadWrite
- Calendars.ReadWrite.Shared
- User.Read
Authenticating with Microsoft Graph
Once you have your API information, you will need to authenticate your solution with the Microsoft Graph API to connect to Outlook Calendar. The sample file at the end of the article has the calls & web viewers that you can reference to set up initial authentication between Outlook and your new Graph application.
When the user clicks Connect button, they will be asked to log in to their Outlook account and approve delegated permissions for the application.
After the user logs in, a FileMaker script parses the redirected page’s URL for the client ID and auth codes that will be used for requests to Outlook.
Making Requests and Parsing the Response
Microsoft Graph API supports multiple types of requests such as HTTP POST, GET and DELETE. You can perform all actions by using native the Insert from URL[] script step and giving it a valid URL and cURL options including required fields within the JSON body specified by the documentation.
Here’s a sample request body to create a calendar event. Note how the DateTime element is formatted. For more details, refer to Microsoft Graph’s properties under the event page.
{ "End" : { "DateTime" : "2018-12-12T11:00:00", "TimeZone" : "Eastern Standard Time" }, "Start" : { "DateTime" : "2018-12-12T10:00:00", "TimeZone" : "Eastern Standard Time" }, "Subject" : "Test 123" }
If you make a successful request, the API will return a JSON-encoded body. You can check if you encountered any errors by looking at the following function after the Insert from URL[ ] step:
Get ( LastExternalErrorDetail )
This function will return 200 on success; otherwise the API encountered an error. If your call was successful, you’ll get response a JSON-encoded response body like below with event ID and change key that you will need to use when updating events:
{ "@odata.context" : "https://graph.microsoft.com/v1.0/$metadata#users('gmoon%40dbservices.com')/calendar/events/$entity", "@odata.etag" : "W/\"eyoqZr4V6UOE23scd9kKdQABYJFSxw==\"", "attendees" : [], "body" : { "content" : "", "contentType" : "text" }, "bodyPreview" : "", "categories" : [], "changeKey" : "eyoqZr4V6UOE23scd9kKdQABYJFSxw==", "createdDateTime" : "2018-12-11T18:26:21.48905Z", "end" : { "dateTime" : "2018-12-12T17:00:00.0000000", "timeZone" : "Eastern Standard Time" }, "hasAttachments" : false, "iCalUId" : "040000008200E00074C5B7101A82E00800000000525905047F91D4010000000000000000100000002EF55A9CBBF9F8429AA5DF86AE8FB2CF", "id" : "AQMkADAwATM3ZmYAZS0wYTI1LWI1N2ItMDACLTAwCgBGAAADVUTIWkB8vk_xO5-ko1YImAcAeyoqAGa_FelDhNt7HHfZCnUAAAIBDQAAAHsqKgBmvhXpQ4Tbexx32Qp1AAFghoJ2AAAA", "importance" : "normal", "isAllDay" : false, "isCancelled" : false, "isOrganizer" : true, "isReminderOn" : true, "lastModifiedDateTime" : "2018-12-11T18:46:23.4155607Z", "location" : { "address" : {}, "coordinates" : {}, "displayName" : "", "locationType" : "default", "uniqueIdType" : "unknown" }, "locations" : [], "onlineMeetingUrl" : null, "organizer" : { "emailAddress" : { "address" : "[email protected]", "name" : "Gayoung Moon" } }, "originalEndTimeZone" : "Eastern Standard Time", "originalStartTimeZone" : "Eastern Standard Time", "recurrence" : null, "reminderMinutesBeforeStart" : 15, "responseRequested" : true, "responseStatus" : { "response" : "organizer", "time" : "0001-01-01T00:00:00Z" }, "sensitivity" : "normal", "seriesMasterId" : null, "showAs" : "busy", "start" : { "dateTime" : "2018-12-12T16:00:00.0000000", "timeZone" : "Eastern Standard Time" }, "subject" : "4 PM Test", "type" : "singleInstance", "webLink" : "https://outlook.live.com/owa/?itemid=AQMkADAwATM3ZmYAZS0wYTI1LWI1N2ItMDACLTAwCgBGAAADVUTIWkB8vk%2BxO5%2Fko1YImAcAeyoqAGa%2BFelDhNt7HHfZCnUAAAIBDQAAAHsqKgBmvhXpQ4Tbexx32Qp1AAFghoJ2AAAA&exvsurl=1&path=/calendar/item" }
Things to Think About
- It’s important to note that if you change permissions on the application registration page, users will have to reauthenticate and give the application those new permissions. Same thing needs to happen if you delete and regenerate your application password for whatever reason.
- Some users won’t have permission to allow application access to their Outlook calendar. Make sure your 365 administrator gives this to each of them before trying to sync calendar events.
- If you want to display a personal calendar in FileMaker via a web viewer, users will need to log in each time that specific layout refreshes. We recommend that you use a public calendar that anyone can see to avoid the need to constantly relog in.
- You will need to refresh your access token at least once every hour, as the token expires after 60 minutes. We recommend that you error trap for HTTP code 401 after a request, refresh the token if there’s a 401, and then retry the original request.
Conclusion
The Microsoft Graph API can help streamline your event and scheduling workflow by giving you the ability to sync your Outlook calendar flawlessly with your FileMaker solution. Contact us if you need help integrating your FileMaker solution with your Outlook Calendar!