PHPackages                             microsoft/microsoft-graph-core - 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. microsoft/microsoft-graph-core

ActiveLibrary[API Development](/categories/api)

microsoft/microsoft-graph-core
==============================

The Microsoft Graph Core SDK for PHP

v2.4.0(5mo ago)152.9M—2.1%5[7 issues](https://github.com/microsoftgraph/msgraph-sdk-php-core/issues)[4 PRs](https://github.com/microsoftgraph/msgraph-sdk-php-core/pulls)4MITPHPPHP ^8.0 || ^7.4CI passing

Since Oct 28Pushed 1mo ago13 watchersCompare

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

READMEChangelog (10)Dependencies (9)Versions (31)Used By (4)Security (1)

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

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

[![Latest Stable Version](https://camo.githubusercontent.com/428c8990118664fbd8b16ec0f6d0b79165f4fc7c2fd08b03d245886323917834/68747470733a2f2f706f7365722e707567782e6f72672f6d6963726f736f66742f6d6963726f736f66742d67726170682d636f72652f76657273696f6e)](https://packagist.org/packages/microsoft/microsoft-graph-core)[![Coverage](https://camo.githubusercontent.com/965c7f3cbedcac15accda5a55797f4b8df9fad785f6038ebcb1dd576943f6455/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6d6963726f736f667467726170685f6d7367726170682d73646b2d7068702d636f7265266d65747269633d636f766572616765)](https://sonarcloud.io/dashboard?id=microsoftgraph_msgraph-sdk-php-core)

Install the Core Library
------------------------

[](#install-the-core-library)

To install the `microsoft-graph-core` library with Composer, either run `composer require microsoft/microsoft-graph-core`, or edit your `composer.json` file:

```
{
    "require": {
        // x-release-please-start-version
        "microsoft/microsoft-graph-core": "^2.4.0"
        // x-release-please-end
    }
}

```

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

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

### 1. Register your application

[](#1-register-your-application)

Register your application to use the Microsoft Graph API by following the steps at [Register an application with the Microsoft Identity platform](https://aka.ms/registerApplication).

### 2. Authenticate with the Microsoft Graph service

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

The Microsoft Graph Core 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, please see [this guide](https://docs.microsoft.com/en-us/graph/auth-v2-service?context=graph%2Fapi%2F1.0&view=graph-rest-1.0) to configure the right permissions.

You can use the [Guzzle HTTP client](http://docs.guzzlephp.org/en/stable/), which comes preinstalled with this library, to get an access token like this:

```
$tokenRequestContext = new ClientCredentialContext(
    'tenantId',
    'clientId',
    'clientSecret'
);
// requests using https://graph.microsoft.com/.default scopes by default
$tokenProvider = new GraphPhpLeagueAccessTokenProvider($tokenRequestContext);
$token = $tokenProvider->getAuthorizationTokenAsync(GraphConstants::REST_ENDPOINT)->wait();
```

### 3. Create a Guzzle HTTP client object

[](#3-create-a-guzzle-http-client-object)

You can create a Guzzle HTTP client object pre-configured for use with the Graph API using our `GraphClientFactory`. The `GraphClientFactory`sets some Guzzle config defaults such as connection and request timeouts, and the `base_uri` to your preferred [National Cloud endpoint](https://docs.microsoft.com/en-us/graph/deployments#microsoft-graph-and-graph-explorer-service-root-endpoints).

In the near future, the `GraphClientFactory` will provide some default middleware to use with the Graph API such as retry handlers.

```
use Microsoft\Graph\Core\GraphClientFactory;

$guzzleConfig = [
    // your preferred guzzle config
];

$httpClient = GraphClientFactory::createWithConfig($guzzleConfig);
```

### 4. Call Microsoft Graph using the v1.0 endpoint

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

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

```
use Microsoft\Graph\Core\GraphClientFactory;

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

        $config = [
            'headers' => [
                'Authorization' => $accessToken
            ]
        ];

        $httpClient = GraphClientFactory::createWithConfig($config);
        $response = $httpClient->get("/v1.0/me");
        $currentUser = json_decode($response->getBody());

        echo "Hello, I am {$currentUser['givenName']}";
    }
}
```

We provide Microsoft Graph models for easy serialization and deserialization.

If you would like to leverage the models we provide, please take a look at the [Microsoft Graph PHP SDK](https://packagist.org/packages/microsoft/microsoft-graph) and for beta models - the [Microsoft Graph Beta PHP SDK](https://packagist.org/packages/microsoft/microsoft-graph-beta).

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

[](#documentation-and-resources)

- [Microsoft Graph website](https://aka.ms/graph)

Develop
-------

[](#develop)

### Run Tests

[](#run-tests)

Run

```
vendor/bin/phpunit
```

from the base directory.

#### 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 `testCreateWithConfigCreatesClient` in *.\\tests\\Http\\GraphClientFactoryTest.php*.
2. Run the **Listen for XDebug** configuration in VS Code.
3. Run `.\vendor\bin\phpunit --filter testCreateWithConfigCreatesClient` from the PowerShell terminal to run the test and hit the breakpoint.

Issues
------

[](#issues)

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

Contribute
----------

[](#contribute)

Please read our [Contributing](https://github.com/microsoftgraph/msgraph-sdk-php-core/blob/main/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

58

—

FairBetter than 98% of packages

Maintenance71

Regular maintenance activity

Popularity52

Moderate usage in the ecosystem

Community32

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~67 days

Recently: every ~130 days

Total

23

Last Release

173d ago

PHP version history (2 changes)2.0.0-RC1PHP ^8.0 || ^7.3

2.0.0-RC4PHP ^8.0 || ^7.4

### Community

Maintainers

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

---

Top Contributors

[![Ndiritu](https://avatars.githubusercontent.com/u/10958912?v=4)](https://github.com/Ndiritu "Ndiritu (370 commits)")[![SilasKenneth](https://avatars.githubusercontent.com/u/11555354?v=4)](https://github.com/SilasKenneth "SilasKenneth (216 commits)")[![MIchaelMainer](https://avatars.githubusercontent.com/u/8527305?v=4)](https://github.com/MIchaelMainer "MIchaelMainer (137 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (29 commits)")[![zengin](https://avatars.githubusercontent.com/u/803311?v=4)](https://github.com/zengin "zengin (22 commits)")[![baywet](https://avatars.githubusercontent.com/u/7905502?v=4)](https://github.com/baywet "baywet (15 commits)")[![andrueastman](https://avatars.githubusercontent.com/u/6464005?v=4)](https://github.com/andrueastman "andrueastman (10 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 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)")[![release-please[bot]](https://avatars.githubusercontent.com/in/40688?v=4)](https://github.com/release-please[bot] "release-please[bot] (5 commits)")[![nokafor](https://avatars.githubusercontent.com/u/10217852?v=4)](https://github.com/nokafor "nokafor (4 commits)")[![adrian05-ms](https://avatars.githubusercontent.com/u/212946016?v=4)](https://github.com/adrian05-ms "adrian05-ms (3 commits)")[![dan-silver](https://avatars.githubusercontent.com/u/1266893?v=4)](https://github.com/dan-silver "dan-silver (3 commits)")[![fey101](https://avatars.githubusercontent.com/u/11347476?v=4)](https://github.com/fey101 "fey101 (3 commits)")[![guilliamxavier](https://avatars.githubusercontent.com/u/7404452?v=4)](https://github.com/guilliamxavier "guilliamxavier (3 commits)")[![landall](https://avatars.githubusercontent.com/u/7061302?v=4)](https://github.com/landall "landall (2 commits)")[![noahheck](https://avatars.githubusercontent.com/u/4154306?v=4)](https://github.com/noahheck "noahheck (2 commits)")[![ronnyjss](https://avatars.githubusercontent.com/u/38010862?v=4)](https://github.com/ronnyjss "ronnyjss (2 commits)")[![osalabs](https://avatars.githubusercontent.com/u/1141095?v=4)](https://github.com/osalabs "osalabs (1 commits)")

---

Tags

devxeng

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)[hubspot/api-client

Hubspot API client

23914.2M16](/packages/hubspot-api-client)[botman/driver-telegram

Telegram driver for BotMan

92437.3k6](/packages/botman-driver-telegram)

PHPackages © 2026

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