Skip to content
Go to file

Latest commit and DriveItem operations

Git stats


Failed to load latest commit information.
Latest commit message
Commit time


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


  1. Installation
  2. Working with SharePoint API
  3. Working with Outlook API
  4. Working with OneDrive API


Total Downloads Latest Stable Version Build Status License


You can use Composer or simply Download the Release


The preferred method is via composer. Follow the installation instructions if you do not already have composer installed.

Once composer is 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": "^2.3"

Finally, be sure to include the autoloader:

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


PHP version: PHP 5.4 or later

Working with SharePoint API

The list of supported SharePoint versions:

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


The following auth flows are supported:

  • app principals (client credentials) auth (refer Granting access using SharePoint App-Only for a details):

     $authCtx = new AuthenticationContext($url);
     $ctx = new ClientContext($url,$authCtx);
  • user credentials auth:

    $authCtx = new AuthenticationContext($url);
    $ctx = new ClientContext($url,$authCtx);
  • NTLM auth (for SharePoint On-Premises):

     $authCtx = new NetworkCredentialContext($username, $password);
     $authCtx->AuthType = CURLAUTH_NTLM;
     $ctx = new ClientContext($url,$authCtx);


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

Example 1. How to read SharePoint list items

$authCtx = new AuthenticationContext($Url);
$authCtx->acquireTokenForUser($UserName,$Password); //authenticate

$ctx = new ClientContext($Url,$authCtx);     
$web = $ctx->getWeb();
$list = $web->getLists()->getByTitle($listTitle); //init List resource
$items = $list->getItems();  //prepare a query to retrieve from the 
$ctx->load($items);  //save a query to retrieve list items from the server 
$ctx->executeQuery(); //submit query to SharePoint Online REST service
foreach( $items->getData() as $item ) {
    print "Task: '{$item->Title}'\r\n";

Example 2. How to create SharePoint list item:

$listTitle = 'Tasks';
$list = $ctx->getWeb()->getLists()->getByTitle($listTitle);
$itemProperties = array('Title' => 'Order Approval', 'Body' => 'Order approval task','__metadata' => array('type' => 'SP.Data.TasksListItem'));
$item = $list->addItem($itemProperties);
print "Task '{$item->Title}' has been created.\r\n";

Example 3. How to delete a SharePoint list item:

$listTitle = 'Tasks';
$itemToDeleteId = 1;
$list = $ctx->getWeb()->getLists()->getByTitle($listTitle);
$listItem = $list->getItemById($itemToDeleteId);

Example 4. How to update SharePoint list item:

$listTitle = 'Tasks';
$itemToUpdateId = 1;
$list = $ctx->getWeb()->getLists()->getByTitle($listTitle);
$listItem = $list->getItemById($itemId);

Working with Outlook API

Supported list of APIs:

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

 $client = new OutlookClient($settings['TenantName'],function (AuthenticationContext $authCtx) {        
        $authCtx->setAccessToken("--access token goes here--");
 $message = $client->getMe()->getMessages()->createMessage();
 $message->Subject = "Meet for lunch?";
 $message->Body = new ItemBody(BodyType::Text,"The new cafeteria is open.");
 $message->ToRecipients = array(
     new Recipient(new EmailAddress(null,""))

Working with OneDrive API

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

$client = new GraphServiceClient($settings['TenantName'],function (AuthenticationContext $authCtx) use($settings) {
      $authCtx->setAccessToken("--access token goes here--");

$drive = $client->getMe()->getDrive();
print $drive->getProperty("webUrl");

You can’t perform that action at this time.