PHPackages                             vgrem/php-spo - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. vgrem/php-spo

ActiveLibrary[HTTP &amp; Networking](/categories/http)

vgrem/php-spo
=============

PHP Office 365 library. It allows to performs CRUD operations against Office 365 resources via an REST/OData based API

v3.2.0(9mo ago)3741.4M—8.2%119[115 issues](https://github.com/vgrem/phpSPO/issues)[1 PRs](https://github.com/vgrem/phpSPO/pulls)5MITPHPPHP &gt;=7.1

Since Apr 20Pushed 8mo ago22 watchersCompare

[ Source](https://github.com/vgrem/phpSPO)[ Packagist](https://packagist.org/packages/vgrem/php-spo)[ Fund](https://paypal.me/ossvgrem)[ GitHub Sponsors](https://github.com/vgrem)[ RSS](/packages/vgrem-php-spo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (30)Used By (5)

About
-----

[](#about)

Microsoft 365 Library for PHP. A REST/OData based client library for Microsoft 365.

### Usage

[](#usage)

1. [Installation](#Installation)
2. [Working with SharePoint API](#Working-with-SharePoint-API)
3. [Working with Teams API](#Working-with-Teams-API)
4. [Working with Outlook API](#Working-with-Outlook-API)
5. [Working with OneDrive API](#Working-with-OneDrive-API)

### Status

[](#status)

[![Total Downloads](https://camo.githubusercontent.com/4f74786c79232289453faf904bd07f3fcb10bc2c2f27906c174044ef2e8f33f9/68747470733a2f2f706f7365722e707567782e6f72672f766772656d2f7068702d73706f2f646f776e6c6f616473)](https://packagist.org/packages/vgrem/php-spo)[![Latest Stable Version](https://camo.githubusercontent.com/3ac3b7d5434e64857bdd1e5da1c040b31ccb2aadc377595ebabe27d296776758/68747470733a2f2f706f7365722e707567782e6f72672f766772656d2f7068702d73706f2f762f737461626c65)](https://packagist.org/packages/vgrem/php-spo)[![Build Status](https://camo.githubusercontent.com/ca33db59d17d6e2341e12302be24726a5009fde195077ae382630d1dcbb69d6f/68747470733a2f2f7472617669732d63692e6f72672f766772656d2f70687053504f2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/vgrem/phpSPO)[![License](https://camo.githubusercontent.com/aa78805d094b21b09a8464ff247d113e39cc46937b000827301ef03d5fef1c12/68747470733a2f2f706f7365722e707567782e6f72672f766772656d2f7068702d73706f2f6c6963656e7365)](https://packagist.org/packages/vgrem/php-spo)

### Installation

[](#installation)

You can use **Composer** or simply **Download the Release**

#### Composer

[](#composer)

The preferred method is via [composer](https://getcomposer.org). Follow the [installation instructions](https://getcomposer.org/doc/00-intro.md) if you do not already have composer installed.

Once composer installed, execute the following command in your project root to install this library:

```
composer require vgrem/php-spo
```

or via `composer.json` file:

```
{
    "require": {
        "vgrem/php-spo": "^3"
    }
}
```

Finally, be sure to include the autoloader:

```
require_once '/path/to/your-project/vendor/autoload.php';

```

#### Requirements

[](#requirements)

PHP version: [PHP 7.1 or later](https://www.php.net/)

#### Working with SharePoint API

[](#working-with-sharepoint-api)

The list of supported SharePoint versions:

- SharePoint Online and OneDrive for Business
- SharePoint On-Premises (2013-2019)

#### Authentication

[](#authentication)

The following auth flows supported:

#### 1. app principal with client credentials:

[](#1-app-principal-with-client-credentials)

```
  use Office365\Runtime\Auth\ClientCredential;
  use Office365\SharePoint\ClientContext;

  $credentials = new ClientCredential("{clientId}", "{clientSecret}");
  $ctx = (new ClientContext("{siteUrl}"))->withCredentials($credentials);
```

Documentation:

- [wiki](https://github.com/vgrem/phpSPO/wiki/How-to-connect-to-SharePoint-Online-and-and-SharePoint-2013-2016-2019-on-premises--with-app-principal)
- [Granting access using SharePoint App-Only](https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs)

#### 2. app principal with client certificate:

[](#2-app-principal-with-client-certificate)

```
  use Office365\Runtime\Auth\ClientCredential;
  use Office365\SharePoint\ClientContext;

$tenant = "{tenant}.onmicrosoft.com"; //tenant id or name
$privateKeyPath = "-- path to private.key file--"
$privateKey = file_get_contents($privateKeyPath);

$ctx = (new ClientContext("{siteUrl}"))->withClientCertificate(
    $tenant, "{clientId}", $privateKey, "{thumbprint}");
```

Documentation:

- [wiki](https://github.com/vgrem/phpSPO/wiki/Granting-access-via-Azure-AD-App%E2%80%90Only-with-Certificate)
- [Granting access using SharePoint App-Only](https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs)

#### 3. user credentials auth:

[](#3-user-credentials-auth)

```
  use Office365\Runtime\Auth\UserCredentials;
  use Office365\SharePoint\ClientContext;

  $credentials = new UserCredentials("{userName}", "{password}");
  $ctx = (new ClientContext("{siteUrl}"))->withCredentials($credentials);
```

#### 4. NTLM auth (for SharePoint On-Premises):

[](#4-ntlm-auth-for-sharepoint-on-premises)

```
   use Office365\Runtime\Auth\UserCredentials;
   use Office365\SharePoint\ClientContext;

   $credentials = new UserCredentials("{userName}", "{password}");
   $ctx = (new ClientContext("{siteUrl}"))->withNtlm($credentials);
```

#### Examples

[](#examples)

The following examples demonstrates how to perform basic CRUD operations against **SharePoint** list item resources:

Example 1. How to read SharePoint list items:

```
use Office365\SharePoint\ClientContext;
use Office365\Runtime\Auth\ClientCredential;
use Office365\SharePoint\ListItem;

$credentials = new ClientCredential("{client-id}", "{client-secret}");
$client = (new ClientContext("https://{your-tenant-prefix}.sharepoint.com"))->withCredentials($credentials);

$web = $client->getWeb();
$list = $web->getLists()->getByTitle("{list-title}"); //init List resource
$items = $list->getItems();  //prepare a query to retrieve from the
$client->load($items);  //save a query to retrieve list items from the server
$client->executeQuery(); //submit query to SharePoint server
/** @var ListItem $item */
foreach($items as $item) {
    print "Task: {$item->getProperty('Title')}\r\n";
}
```

or via fluent API syntax:

```
use Office365\SharePoint\ClientContext;
use Office365\Runtime\Auth\ClientCredential;
use Office365\SharePoint\ListItem;

$credentials = new ClientCredential("{client-id}", "{client-secret}");
$client = (new ClientContext("https://{your-tenant-prefix}.sharepoint.com"))->withCredentials($credentials);

$items = $client->getWeb()
                ->getLists()
                ->getByTitle("{list-title}")
                ->getItems()
                ->get()
                ->executeQuery();
/** @var ListItem $item */
foreach($items as $item) {
    print "Task: {$item->getProperty('Title')}\r\n";
}
```

Example 2. How to create SharePoint list item:

```
use Office365\SharePoint\ClientContext;
use Office365\Runtime\Auth\ClientCredential;

$credentials = new ClientCredential("{client-id}", "{client-secret}");
$client = (new ClientContext("https://{your-tenant-prefix}.sharepoint.com"))->withCredentials($credentials);

$list = $client->getWeb()->getLists()->getByTitle("Tasks");
$itemProperties = array('Title' => 'Order Approval', 'Body' => 'Order approval task');
$item = $list->addItem($itemProperties)->executeQuery();
print "Task {$item->getProperty('Title')} has been created.\r\n";
```

Example 3. How to delete a SharePoint list item:

```
use Office365\SharePoint\ClientContext;
use Office365\Runtime\Auth\ClientCredential;

$credentials = new ClientCredential("{client-id}", "{client-secret}");
$client = (new ClientContext("https://{your-tenant-prefix}.sharepoint.com"))->withCredentials($credentials);

$list = $client->getWeb()->getLists()->getByTitle("Tasks");
$listItem = $list->getItemById("{item-id-to-delete}");
$listItem->deleteObject()->executeQuery();
```

Example 4. How to update SharePoint list item:

```
use Office365\SharePoint\ClientContext;
use Office365\Runtime\Auth\ClientCredential;

$credentials = new ClientCredential("{client-id}", "{client-secret}");
$client = (new ClientContext("https://{your-tenant-prefix}.sharepoint.com"))->withCredentials($credentials);

$list = $client->getWeb()->getLists()->getByTitle("Tasks");
$listItem = $list->getItemById("{item-id-to-update}");
$listItem->setProperty('PercentComplete',1);
$listItem->update()->executeQuery();
```

### Working with Teams API

[](#working-with-teams-api)

#### Example: create a Team

[](#example-create-a-team)

The following is an example of a minimal request to create a Team (via delegated permissions)

```
use Office365\GraphServiceClient;
use Office365\Runtime\Auth\AADTokenProvider;
use Office365\Runtime\Auth\UserCredentials;

function acquireToken()
{
    $tenant = "{tenant}.onmicrosoft.com";
    $resource = "https://graph.microsoft.com";

    $provider = new AADTokenProvider($tenant);
    return $provider->acquireTokenForPassword($resource, "{clientId}",
        new UserCredentials("{UserName}", "{Password}"));
}

$client = new GraphServiceClient("acquireToken");
$teamName = "My Sample Team";
$newTeam = $client->getTeams()->add($teamName)->executeQuery();
```

### Working with Outlook API

[](#working-with-outlook-api)

Supported list of APIs:

- [Outlook REST API](https://msdn.microsoft.com/en-us/office/office365/api/use-outlook-rest-api#DefineOutlookRESTAPI)
    - [Outlook Contacts REST API](https://msdn.microsoft.com/en-us/office/office365/api/contacts-rest-operations)
    - [Outlook Calendar REST API](https://msdn.microsoft.com/en-us/office/office365/api/calendar-rest-operations)
    - [Outlook Mail REST API](https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations)

The following example demonstrates how to send a message via Outlook Mail API:

```
 use Office365\GraphServiceClient;
 use Office365\Outlook\Message;
 use Office365\Outlook\ItemBody;
 use Office365\Outlook\BodyType;
 use Office365\Outlook\EmailAddress;
 use Office365\Runtime\Auth\AADTokenProvider;
 use Office365\Runtime\Auth\UserCredentials;

function acquireToken()
{
    $tenant = "{tenant}.onmicrosoft.com";
    $resource = "https://graph.microsoft.com";

    $provider = new AADTokenProvider($tenant);
    return $provider->acquireTokenForPassword($resource, "{clientId}",
        new UserCredentials("{UserName}", "{Password}"));
}

$client = new GraphServiceClient("acquireToken");
/** @var Message $message */
$message = $client->getMe()->getMessages()->createType();
$message->setSubject("Meet for lunch?");
$message->setBody(new ItemBody(BodyType::Text,"The new cafeteria is open."));
$message->setToRecipients([new EmailAddress(null,"fannyd@contoso.onmicrosoft.com")]);
$client->getMe()->sendEmail($message,true)->executeQuery();
```

### Working with OneDrive API

[](#working-with-onedrive-api)

The following example demonstrates how retrieve My drive Url via OneDrive API:

```
use Office365\GraphServiceClient;
use Office365\Runtime\Auth\AADTokenProvider;
use Office365\Runtime\Auth\UserCredentials;

function acquireToken()
{
    $tenant = "{tenant}.onmicrosoft.com";
    $resource = "https://graph.microsoft.com";

    $provider = new AADTokenProvider($tenant);
    return $provider->acquireTokenForPassword($resource, "{clientId}",
        new UserCredentials("{UserName}", "{Password}"));
}

$client = new GraphServiceClient("acquireToken");
$drive = $client->getMe()->getDrive()->get()->executeQuery();
print $drive->getWebUrl();
```

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance52

Moderate activity, may be stable

Popularity61

Solid adoption and visibility

Community38

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 86.6% 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 ~108 days

Recently: every ~191 days

Total

29

Last Release

274d ago

Major Versions

v2.5.4 → v3.0.02022-10-07

PHP version history (3 changes)v2.1.8PHP &gt;=5.4

v2.4.1PHP &gt;=5.5

v3.0.0PHP &gt;=7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/366059?v=4)[Marc Wustrack](/maintainers/muffe)[@muffe](https://github.com/muffe)

---

Top Contributors

[![vgrem](https://avatars.githubusercontent.com/u/1596072?v=4)](https://github.com/vgrem "vgrem (382 commits)")[![cweiske](https://avatars.githubusercontent.com/u/59036?v=4)](https://github.com/cweiske "cweiske (9 commits)")[![blizzz](https://avatars.githubusercontent.com/u/2184312?v=4)](https://github.com/blizzz "blizzz (8 commits)")[![johnpc](https://avatars.githubusercontent.com/u/4824042?v=4)](https://github.com/johnpc "johnpc (6 commits)")[![ctcudd](https://avatars.githubusercontent.com/u/3977194?v=4)](https://github.com/ctcudd "ctcudd (5 commits)")[![mpastas](https://avatars.githubusercontent.com/u/1851992?v=4)](https://github.com/mpastas "mpastas (3 commits)")[![andreybolonin](https://avatars.githubusercontent.com/u/2576509?v=4)](https://github.com/andreybolonin "andreybolonin (2 commits)")[![drml](https://avatars.githubusercontent.com/u/5463003?v=4)](https://github.com/drml "drml (2 commits)")[![fr3nch13](https://avatars.githubusercontent.com/u/7828?v=4)](https://github.com/fr3nch13 "fr3nch13 (2 commits)")[![prog-24](https://avatars.githubusercontent.com/u/2653516?v=4)](https://github.com/prog-24 "prog-24 (2 commits)")[![thijsvdanker](https://avatars.githubusercontent.com/u/429548?v=4)](https://github.com/thijsvdanker "thijsvdanker (2 commits)")[![VincentFoulon80](https://avatars.githubusercontent.com/u/26797476?v=4)](https://github.com/VincentFoulon80 "VincentFoulon80 (2 commits)")[![vroomfondle](https://avatars.githubusercontent.com/u/6186584?v=4)](https://github.com/vroomfondle "vroomfondle (2 commits)")[![lbuchs](https://avatars.githubusercontent.com/u/37619779?v=4)](https://github.com/lbuchs "lbuchs (1 commits)")[![mahmudz](https://avatars.githubusercontent.com/u/22455598?v=4)](https://github.com/mahmudz "mahmudz (1 commits)")[![MathieuMenegain](https://avatars.githubusercontent.com/u/15829795?v=4)](https://github.com/MathieuMenegain "MathieuMenegain (1 commits)")[![DavidBrogli](https://avatars.githubusercontent.com/u/23071343?v=4)](https://github.com/DavidBrogli "DavidBrogli (1 commits)")[![nkgokul](https://avatars.githubusercontent.com/u/1375897?v=4)](https://github.com/nkgokul "nkgokul (1 commits)")[![pockemul](https://avatars.githubusercontent.com/u/6992719?v=4)](https://github.com/pockemul "pockemul (1 commits)")[![ChangingTerry](https://avatars.githubusercontent.com/u/5968506?v=4)](https://github.com/ChangingTerry "ChangingTerry (1 commits)")

---

Tags

microsoft-graphmicrosoft365office365office365-sdkonedriveonenoteoutlookoutlook-365phpplannersdksharepointteamsapirestcurlOffice365microsoftgraph

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vgrem-php-spo/health.svg)

```
[![Health](https://phpackages.com/badges/vgrem-php-spo/health.svg)](https://phpackages.com/packages/vgrem-php-spo)
```

###  Alternatives

[nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

1.8k17.2M267](/packages/nategood-httpful)[xeroapi/xero-php-oauth2

Xero official PHP SDK for oAuth2 generated with OpenAPI spec 3

1054.3M14](/packages/xeroapi-xero-php-oauth2)[bigcommerce/api

Enables PHP applications to communicate with the Bigcommerce API.

1501.1M8](/packages/bigcommerce-api)[arhitector/yandex

PHP SDK для работы с некоторыми сервисами яндекса (Яндекс.Диск, Yandex.Disk)

13082.9k5](/packages/arhitector-yandex)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69114.3k](/packages/serpapi-google-search-results-php)[ismaeltoe/osms

PHP library wrapper of the Orange SMS API.

4540.0k](/packages/ismaeltoe-osms)

PHPackages © 2026

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