PHPackages                             rayafort/microsoft-graph - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. rayafort/microsoft-graph

ActiveLibrary[API Development](/categories/api)

rayafort/microsoft-graph
========================

The Microsoft Graph SDK for PHP

v2.0.1(5y ago)048MITPHPPHP ^8.0 || ^7.1

Since Dec 15Pushed 5y agoCompare

[ Source](https://github.com/rayafort/msgraph-sdk-php)[ Packagist](https://packagist.org/packages/rayafort/microsoft-graph)[ Docs](https://developer.microsoft.com/en-us/graph)[ RSS](/packages/rayafort-microsoft-graph/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (4)Versions (35)Used By (0)

Get started with the Microsoft Graph SDK for PHP
================================================

[](#get-started-with-the-microsoft-graph-sdk-for-php)

[![Build Status](https://camo.githubusercontent.com/ef27ad2349d87cda70d9c433d672da78dd082d86886531152a6304e58b757b9d/68747470733a2f2f7472617669732d63692e6f72672f6d6963726f736f667467726170682f6d7367726170682d73646b2d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/microsoftgraph/msgraph-sdk-php)[![Latest Stable Version](https://camo.githubusercontent.com/63ab915a25d54ca24c223837d19fdbf629f0ed30573495975abd00294e7d8093/68747470733a2f2f706f7365722e707567782e6f72672f6d6963726f736f66742f6d6963726f736f66742d67726170682f76657273696f6e)](https://packagist.org/packages/microsoft/microsoft-graph)

Get started with the PHP Connect Sample
---------------------------------------

[](#get-started-with-the-php-connect-sample)

If you want to play around with the PHP library, you can get up and running quickly with the [PHP Connect Sample](https://github.com/microsoftgraph/php-connect-sample). This sample will start you with a little Laravel project that helps you with registration, authentication, and making a simple call to the service.

Install the SDK
---------------

[](#install-the-sdk)

You can install the PHP SDK with Composer, either run `composer require microsoft/microsoft-graph`, or edit your `composer.json` file:

```
{
    "require": {
        "microsoft/microsoft-graph": "^1.20"
    }
}

```

Get started with Microsoft Graph
--------------------------------

[](#get-started-with-microsoft-graph)

### Register your application

[](#register-your-application)

Register your application to use the Microsoft Graph API using [Microsoft Azure Active Directory](https://manage.windowsazure.com) in your tenant's Active Directory to support work or school users for your tenant, or multiple tenants.

### Authenticate with the Microsoft Graph service

[](#authenticate-with-the-microsoft-graph-service)

The Microsoft Graph SDK for PHP does not include any default authentication implementations. The [`thephpleague/oauth2-client`](https://github.com/thephpleague/oauth2-client) library will handle the OAuth2 flow for you and provide a usable token for querying the Graph.

To authenticate as an application you can use the [Guzzle HTTP client](http://docs.guzzlephp.org/en/stable/), which comes preinstalled with this library, for example like this:

```
$guzzle = new \GuzzleHttp\Client();
$url = 'https://login.microsoftonline.com/' . $tenantId . '/oauth2/token?api-version=1.0';
$token = json_decode($guzzle->post($url, [
    'form_params' => [
        'client_id' => $clientId,
        'client_secret' => $clientSecret,
        'resource' => 'https://graph.microsoft.com/',
        'grant_type' => 'client_credentials',
    ],
])->getBody()->getContents());
$accessToken = $token->access_token;
```

For an integrated example on how to use Oauth2 in a Laravel application and use the Graph, see the [PHP Connect Sample](https://github.com/microsoftgraph/php-connect-sample).

### Call Microsoft Graph using the v1.0 endpoint and models

[](#call-microsoft-graph-using-the-v10-endpoint-and-models)

The following is an example that shows how to call Microsoft Graph.

```
use Microsoft\Graph\Graph;
use Microsoft\Graph\Model;

class UsageExample
{
    public function run()
    {
        $accessToken = 'xxx';

        $graph = new Graph();
        $graph->setAccessToken($accessToken);

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

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

### Call Microsoft Graph using the beta endpoint and models

[](#call-microsoft-graph-using-the-beta-endpoint-and-models)

The following is an example that shows how to call Microsoft Graph.

```
use Microsoft\Graph\Graph;
use Beta\Microsoft\Graph\Model as BetaModel;

class UsageExample
{
    public function run()
    {
        $accessToken = 'xxx';

        $graph = new Graph();
        $graph->setAccessToken($accessToken);

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

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

Develop
-------

[](#develop)

### Debug

[](#debug)

You can use the library with a proxy such as [Fiddler](http://www.telerik.com/fiddler) or [Charles Proxy](https://www.charlesproxy.com/) to debug requests and responses as they come across the wire. Set the proxy port on the Graph object like this:

```
$graph->setProxyPort("localhost:8888");
```

Then, open your proxy client to view the requests &amp; responses sent using the library.

[![Screenshot of Fiddler /me/sendmail request and response](https://github.com/microsoftgraph/msgraph-sdk-php/raw/master/docs/images/Fiddler.PNG)](https://github.com/microsoftgraph/msgraph-sdk-php/blob/master/docs/images/Fiddler.PNG)

This is especially helpful when the library does not return the results you expected to determine whether there are bugs in the API or this SDK. Therefore, you may be asked to provide this information when attempting to triage an issue you file.

### Run Tests

[](#run-tests)

Run

```
vendor/bin/phpunit --exclude-group functional
```

from the base directory.

*The set of functional tests are meant to be run against a test account. Currently, the tests to do not restore state of the account.*

#### Debug tests on Windows

[](#debug-tests-on-windows)

This SDK has an XDebug run configuration that attaches the debugger to VS Code so that you can debug tests.

1. Install the [PHP Debug](https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug) extension into Visual Studio Code.
2. From the root of this repo, using PowerShell, run `php .\tests\GetPhpInfo.php | clip` from the repo root. This will copy PHP configuration information into the clipboard which we will use in the next step.
3. Paste your clipboard into the [XDebug Installation Wizard](https://xdebug.org/wizard) and select **Analyse my phpinfo() output**.
4. Follow the generated instructions for installing XDebug. Note that the `/ext` directory is located in your PHP directory.
5. Add the following info to your php.ini file:

```
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1

```

Now you can hit a Visual Studio Code breakpoint in a test. Try this:

1. Add a breakpoint to `testGetCalendarView` in *.\\tests\\Functional\\EventTest.php*.
2. Run the **Listen for XDebug** configuration in VS Code.
3. Run `.\vendor\bin\phpunit --filter testGetCalendarView` from the PowerShell terminal to run the test and hit the breakpoint.

Documentation and resources
---------------------------

[](#documentation-and-resources)

- [Documentation](https://github.com/microsoftgraph/msgraph-sdk-php/blob/master/docs/index.html)
- [Wiki](https://github.com/microsoftgraph/msgraph-sdk-php/wiki)
- [Examples](https://github.com/microsoftgraph/msgraph-sdk-php/wiki/Example-calls)
- [Microsoft Graph website](https://developer.microsoft.com/en-us/graph/)

Issues
------

[](#issues)

View or log issues on the [Issues](https://github.com/microsoftgraph/msgraph-sdk-php/issues) tab in the repo.

Contribute
----------

[](#contribute)

Please read our [Contributing](https://github.com/microsoftgraph/msgraph-sdk-php/blob/master/CONTRIBUTING.md) guidelines carefully for advice on how to contribute to this repo.

Copyright and license
---------------------

[](#copyright-and-license)

Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT [license](LICENSE).

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact  with any additional questions or comments.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 69.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~45 days

Recently: every ~22 days

Total

34

Last Release

1941d ago

Major Versions

0.1.1 → 1.0.02017-05-10

1.25.0 → v2.0.02021-01-23

PHP version history (3 changes)0.1.0PHP ^5.6 || ^7.0

1.13.0PHP ^7.1

v2.0.0PHP ^8.0 || ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/d0fc2889c47f9b45132fbd2ddded9d07ba13f0d46fc0ac896f8e18ca25d2b25e?d=identicon)[wsenjer](/maintainers/wsenjer)

---

Top Contributors

[![MIchaelMainer](https://avatars.githubusercontent.com/u/8527305?v=4)](https://github.com/MIchaelMainer "MIchaelMainer (113 commits)")[![zengin](https://avatars.githubusercontent.com/u/803311?v=4)](https://github.com/zengin "zengin (10 commits)")[![curry684](https://avatars.githubusercontent.com/u/1455673?v=4)](https://github.com/curry684 "curry684 (8 commits)")[![Zombaya](https://avatars.githubusercontent.com/u/13340313?v=4)](https://github.com/Zombaya "Zombaya (6 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (5 commits)")[![nokafor](https://avatars.githubusercontent.com/u/10217852?v=4)](https://github.com/nokafor "nokafor (4 commits)")[![dan-silver](https://avatars.githubusercontent.com/u/1266893?v=4)](https://github.com/dan-silver "dan-silver (3 commits)")[![noahheck](https://avatars.githubusercontent.com/u/4154306?v=4)](https://github.com/noahheck "noahheck (2 commits)")[![wsenjer](https://avatars.githubusercontent.com/u/132250?v=4)](https://github.com/wsenjer "wsenjer (2 commits)")[![landall](https://avatars.githubusercontent.com/u/7061302?v=4)](https://github.com/landall "landall (2 commits)")[![osalabs](https://avatars.githubusercontent.com/u/1141095?v=4)](https://github.com/osalabs "osalabs (1 commits)")[![tdondich](https://avatars.githubusercontent.com/u/3330334?v=4)](https://github.com/tdondich "tdondich (1 commits)")[![tolbon](https://avatars.githubusercontent.com/u/768394?v=4)](https://github.com/tolbon "tolbon (1 commits)")[![iampoul](https://avatars.githubusercontent.com/u/496452?v=4)](https://github.com/iampoul "iampoul (1 commits)")[![anvanza](https://avatars.githubusercontent.com/u/2848347?v=4)](https://github.com/anvanza "anvanza (1 commits)")[![Levure](https://avatars.githubusercontent.com/u/1922257?v=4)](https://github.com/Levure "Levure (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![guilliamxavier](https://avatars.githubusercontent.com/u/7404452?v=4)](https://github.com/guilliamxavier "guilliamxavier (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rayafort-microsoft-graph/health.svg)

```
[![Health](https://phpackages.com/badges/rayafort-microsoft-graph/health.svg)](https://phpackages.com/packages/rayafort-microsoft-graph)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
