PHPackages                             gwsn/sharepoint-sdk - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. gwsn/sharepoint-sdk

ActiveLibrary[File &amp; Storage](/categories/file-storage)

gwsn/sharepoint-sdk
===================

Connect to sharepoint drive with PHP

1.2.0(2y ago)774.6k↑17.7%11[1 issues](https://github.com/gwsn/sharepoint-sdk/issues)[2 PRs](https://github.com/gwsn/sharepoint-sdk/pulls)1MITPHPPHP ^8.0

Since Feb 8Pushed 2y ago1 watchersCompare

[ Source](https://github.com/gwsn/sharepoint-sdk)[ Packagist](https://packagist.org/packages/gwsn/sharepoint-sdk)[ Docs](https://github.com/gwsn/sharepoint-sdk)[ RSS](/packages/gwsn-sharepoint-sdk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (11)Used By (1)

sharepoint-sdk for the Sharepoint Graph API
===========================================

[](#sharepoint-sdk-for-the-sharepoint-graph-api)

Sharepoint SDK to use Sharepoint as filestorage.

For the Flysystem adapter (Symfony and Laravel) see the flysystem package: [gwsn/flysystem-sharepoint-adapter](https://github.com/gwsn/flysystem-sharepoint-adapter)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require gwsn/sharepoint-sdk
```

First configuration to start usage
----------------------------------

[](#first-configuration-to-start-usage)

You need to request a new clientId and clientSecret for a new application on Azure.

1. Go to `Azure portal`
2. Go to `Azure Active Directory`
3. Go to `App registrations`
4. Click on `new Registration` and follow the wizard.
    (give it a name like mine is 'gwsn-sharepoint-connector' and make a decision on the supported accounts, single tenant should be enough but this depends on your organisation)
5. When created the application is created write down the following details
6. 'Application (client) id', this will be your `$clientId`
7. 'Directory (tenant) id', this will be your `$tenantId`
8. Then we go in the menu to the `API permissions` to set the permissions that are required
9. The click on `Add a permission` and add the following permissions:
    Microsoft Graph:

    - Files.ReadWrite.All
    - Sites.ReadWrite.All
    - User.Read
10. Click on the `Grant admin consent for ...Company...`
11. Go in the menu to `Certificates & secrets`
12. Click on `new client secret`
13. Give it a description and expiry date and the value will be your `$clientSecret`
14. The last parameter will be the sharepoint 'slug', this is part of the url of the sharepoint site what you want to use and creation of sharepoint site is out of scope of this readme.
    When you sharepoint url is like `https://{tenant}.sharepoint.com/sites/{site-slug}/Shared%20Documents/Forms/AllItems.aspx`
    You need to set the `$sharepointSite` as `{site-slug}`

    Example:

    - Sharepoint site url: `https://GWSN.sharepoint.com/sites/gwsn-documents-store/Shared%20Documents/Forms/AllItems.aspx`
    - Sharepoint site variable: `$sharepointSite = 'gwsn-documents-store'`

Basic usage with the flysystem adapter (preferred way!)
-------------------------------------------------------

[](#basic-usage-with-the-flysystem-adapter-preferred-way)

```
use GWSN\FlysystemSharepoint\FlysystemSharepointAdapter;
use GWSN\FlysystemSharepoint\SharepointConnector;
use League\Flysystem\Filesystem;

$tenantId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
$clientId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
$clientSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$sharepointSite = 'your-path-to-your-site';

$connector = new SharepointConnector($tenantId, $clientId, $clientSecret, $sharepointSite);

$prefix = '/test'; // optional
$adapter = new FlysystemSharepointAdapter($connector, $prefix);

$flysystem = new Filesystem($adapter);
```

Basic needs to be able to use the folder|drive|file service
-----------------------------------------------------------

[](#basic-needs-to-be-able-to-use-the-folderdrivefile-service)

```
use GWSN\Microsoft\Authentication\AuthenticationService;
use GWSN\Microsoft\Drive\DriveService;
use GWSN\Microsoft\Drive\FileService;
use GWSN\Microsoft\Drive\FolderService;
use GWSN\Microsoft\Sharepoint\SharepointService;

// Not needed if you use a framework with dependency injection !
require dirname(dirname(__DIR__)) . '/vendor/autoload.php';

$tenantId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
$clientId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
$clientSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

$sharepointSite = 'your-path-to-your-site';

// Login into MS oauth and fetch new access token
// In real application please save the access token and use it until it expires
$authService = new AuthenticationService();
$accessToken = $authService->getAccessToken($tenantId, $clientId, $clientSecret);
```

Usage for managing for Sharepoint drives
----------------------------------------

[](#usage-for-managing-for-sharepoint-drives)

include the basic usage and add the following code

```
    // Initialize the drive
    $spDrive = new DriveService($accessToken);
    $driveId = $spDrive->requestDriveId($siteId);
    $spDrive->setDriveId($driveId);

     // Check if Resource exists
    try {
        $result = $spDrive->checkResourceExists('/test');
        var_dump($result);
        $result = $spDrive->checkResourceExists('/testDoc.docx');
        var_dump($result);
    } catch (\Exception $exception) {
        var_dump($exception->getMessage());
    }

    // move file /test.txt to folder /test and rename it to testje.txt
    $result = $spFileService->moveFile('/test.txt', '/test', 'testje.txt');

    // check if it still exists
    $result = $spDrive->checkResourceExists('/test.txt');
    var_dump($result);

    // check if new file exists
    $result = $spDrive->checkResourceExists('/test/testje.txt');
    var_dump($result);

```

Usage for managing Sharepoint folders
-------------------------------------

[](#usage-for-managing-sharepoint-folders)

include the basic usage and add the following code

```
try {
    // Initialize the drive
    $spDrive = new DriveService($accessToken);
    $driveId = $spDrive->requestDriveId($siteId);
    $spDrive->setDriveId($driveId);

    // Create the folderService
    $spFolderService = new FolderService($accessToken, $driveId);

    // Get files from sharepoint folder
    $listRootDirResult = $spFolderService->requestFolderItems('/');

    // Check if Folder exists
    $spFolderService->checkFolderExists('/test');

    // Get files from sharepoint sub folder
    $listRootDirResult = $spFolderService->requestFolderItems('/test');

    // Get Folder from sharepoint
    $spFolderService->createFolderRecursive('/dummy/test');

    // Delete Folder from sharepoint we just created
    $spFolderService->deleteFolder('/dummy/test');
    $spFolderService->deleteFolder('/dummy');

    // Check if Folder exists while its a file
    try {
        $result = $spFolderService->checkFolderExists('/testDoc.docx');
        var_dump($result);
    } catch (\Exception $exception) {
        var_dump($exception->getMessage());
    }

} catch (\Exception $exception) {
    var_dump($exception->getMessage());
}
```

Usage for files in Sharepoint drives
------------------------------------

[](#usage-for-files-in-sharepoint-drives)

include the basic usage and add the following code

```
    // FileService
    $spFileService = new FileService($accessToken, $driveId);

    // write file to directory
    $result = $spFileService->writeFile('/test.txt', 'testContent');
    var_dump(isset($result['id']));

    // read file from directory
    $content = $spFileService->readFile('/test.txt');
    var_dump(($content === 'testContent'));

    // write file to directory
    $result = $spFileService->writeFile('/test/docje.txt', 'testContent');
    var_dump(isset($result['id']));

    // read file from directory
    $content = $spFileService->readFile('/test/docje.txt');
    var_dump(($content === 'testContent'));

    // move file
    $result = $spFileService->moveFile('/test.txt', '/test', 'testje.txt');
    $result = $spDrive->checkResourceExists('/test.txt');
    var_dump($result);
    $result = $spDrive->checkResourceExists('/test/testje.txt');
    var_dump($result);

    // copy file
    $result = $spFileService->copyFile('/test/testje.txt', '/', 'toBeDeleted.txt');
    var_dump($result);
    // copy dir
    $result = $spFileService->copyFile('/test', '/test2');
    var_dump($result);

    // delete file from directory
    $content = $spFileService->deleteFile('/test/testje.txt');
    var_dump($content);
    $content = $spFileService->deleteFile('/test/docje.txt');
    var_dump($content);
    $content = $spFileService->deleteFile('/toBeDeleted.txt');
    var_dump($content);
    $content = $spFileService->deleteFile('/test.txt');
    var_dump($content);
```

Testing
-------

[](#testing)

```
$ composer run-script test
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 87.2% 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 ~75 days

Recently: every ~112 days

Total

9

Last Release

956d ago

PHP version history (2 changes)1.0.0PHP ^7.4 || ^8.0

1.1.0PHP ^8.0

### Community

Maintainers

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

---

Top Contributors

[![jnovermars](https://avatars.githubusercontent.com/u/4355811?v=4)](https://github.com/jnovermars "jnovermars (34 commits)")[![KarelBrijs](https://avatars.githubusercontent.com/u/16884712?v=4)](https://github.com/KarelBrijs "KarelBrijs (3 commits)")[![adiwit-co-th](https://avatars.githubusercontent.com/u/50860673?v=4)](https://github.com/adiwit-co-th "adiwit-co-th (2 commits)")

---

Tags

Flysystemsharepoint

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gwsn-sharepoint-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/gwsn-sharepoint-sdk/health.svg)](https://phpackages.com/packages/gwsn-sharepoint-sdk)
```

###  Alternatives

[masbug/flysystem-google-drive-ext

Flysystem adapter for Google Drive with seamless virtual&lt;=&gt;display path translation

2631.7M14](/packages/masbug-flysystem-google-drive-ext)[shitware-ltd/flysystem-msgraph

A Flysystem 3.0 adapter for Sharepoint 365 / OneDrive using Microsoft Graph API with support for uploading large files

19360.4k3](/packages/shitware-ltd-flysystem-msgraph)[gwsn/flysystem-sharepoint-adapter

\[beta\] Adapter for flysystem to use sharepoint as filestore

1765.8k](/packages/gwsn-flysystem-sharepoint-adapter)[jacekbarecki/flysystem-onedrive

OneDrive adapter for the flysystem filesystem abstraction library

2429.9k](/packages/jacekbarecki-flysystem-onedrive)[royvoetman/flysystem-gitlab-storage

Flysystem Adapter for the Gitlab Repository files API v4

1123.3k4](/packages/royvoetman-flysystem-gitlab-storage)[quix-labs/laravel-supabase-flysystem

Supabase Adapter for Laravel Flysystem Storage

169.9k](/packages/quix-labs-laravel-supabase-flysystem)

PHPackages © 2026

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