Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Microsoft Graph API

Security covered No further development 171 sites

This module provides a lightweight wrapper for the Microsoft Graph SDK, making it easier for custom Drupal modules to interact with the Microsoft Graph API. It allows developers to obtain a default API client or instantiate clients with custom keys.

An unofficial, lightweight wrapper around the
Microsoft Graph SDK for PHP,
pulled-in via Composer, for Drupal 8.x.

Use Case

This module is intended to provide an API for other modules to easily obtain
either a site-wide "default" instance of the MS Graph API client using service
injection, or to be able to instantiate an API client using any number of
custom keys.

This module does not provide site builders or end users with any additional
functionality. Install it only if you are developing a custom module or are
using a module that indicates it depends on this module.

Usage

Installation

It is recommended to install this via Composer so that the required version of
the Graph API PHP SDK can be pulled in.

composer require 'drupal/ms_graph_api'

Registration and Configuration

See the README for instructions on how to register your Drupal site with Azure and configure keys.

Obtaining Graph Instances

Afterwards, you can obtain the default, authenticated API graph by getting the
ms_graph_api.graph service and then calling any of the methods on the object
you get back that are
documented for the PHP library.
For example, in procedural code and hooks:

use Microsoft\Graph\Model;

$graph = \Drupal::service('ms_graph_api.graph');

$user =
  $graph
    ->createRequest("GET", "/me")
    ->setReturnType(Model\User::class)
    ->execute();

echo "Hello, I am {$user->getGivenName()}.";

Getting a MS Graph API Graph for a Custom Key

If your site needs to work with multiple Azure subscriptions, you do not need
to configure the default key. Instead, define custom keys (of type
"MS Graph API Key") for each of the different deployments, obtain the Graph
API graph factory service, and construct a different API client for each custom
key.

For example:

use Microsoft\Graph\Model;

$graph_factory = \Drupal::service('ms_graph_api.graph.factory');
$graph = $client_factory->buildGraphFromKeyId('my_graph_api_key');

$user =
  $graph
    ->createRequest("GET", "/me")
    ->setReturnType(Model\User::class)
    ->execute();

echo "Hello, I am {$user->getGivenName()}.";
Drupal 9–10 · not 11

Ask your assistant about Microsoft Graph API

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
5
Tracked since
Jul 2023
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 3
Maintenance
Slowing

Release Timeline

Releases

Version Type Core PHP Release date
2.0.0-beta2 Pre-release 9–11 Sep 5, 2025
2.0.0-beta1 Pre-release 9–10 Sep 5, 2025
2.x-dev Dev 9–11 Sep 5, 2025
1.1.0 Stable 9–10 Jul 6, 2023
1.x-dev Dev 9–10 Jul 6, 2023