Extending the Office 365 Connector module

4 minuten lezen

Using the Office 365 Connector module it is possible for developers to connect to the Graph API's from Microsoft.

How to start

First of all we need to know what we want to get from, or send to, Microsoft. For this blog I would like to show you how to search for files in SharePoint, but there are a lot more API's available.

Microsoft offers good documentation and a Graph Explorer. Using the Graph Explorer you can test the endpoints and see what data is returned when you do a request.

Custom scopes

When developing it can happen that the scopes the default Office connector module or one of its submodules use isn’t sufficient.

When that happens you can use a custom hook we have added to the module. This hook adds the authorization scopes when logging in to Office and makes the data in the Graph API accessible for the Office 365 connector.

Get data from the Graph API

To retrieve data from the Graph API we have created a service for you called the GraphService. When using this service you have all the benefits of the Office 365 connector. This service already takes in account your status, and retrieves data from the Graph API as the current logged in user.

As you can see in the screenshot it is really easy to use. The getGraphData method in the service returns the data retrieved from the Graph API as is so you can do your own magic with it.

The first parameter for the method is the endpoint in the Graph API which you can find in the Graph Explorer at Microsoft.com.

Post data to the Graph API

To post data to the Graph API you can use the sendGraphData method in the service. Just add the endpoint you would like to post to, and the data structure and you’re done! In the code example you can see how an event is created in my Outlook Calendar.

And now?

Do you want to know more? Take a look at the project page on Drupal.org. And for any questions, please add an issue to the issue queue or ask support questions on our slack channel.

Photo by Ryan Quintal on Unsplash

Meer weten

fabian.de.rijk

Senior Drupal Developer0640869887[email protected]0640869887LinkedInTwitterDrupal
Meer van fabian.de.rijk

Meer artikelen

drupal
Drupal 8
drupal 9
drupal 10
content management
migration
migrate
developers

Dummy content with Migrate

9 minuten lezen
Lees het artikel Dummy content with Migrate
Editor training
CMS knowledge

Finalist Editor Training

4 minuten lezen
Lees het artikel Finalist Editor Training
wcag
drupal
layout
content management

Some highlights from the Drupal Developer Days 2022

12 minuten lezen
Lees het artikel Some highlights from the Drupal Developer Days 2022