A simple PHP API to make working with SharePoint lists easy.

Overview

PHP SharePoint Lists API

The PHP SharePoint Lists API is designed to make working with SharePoint Lists in PHP a less painful developer experience. Rather than messing around with SOAP and CAML requests, just include the SharePoint lists API in to your project and you should be good to go. This library is free for anyone to use and is licensed under the MIT license.

Using the PHP SharePoint Lists API, you can easily create, read, edit and delete from SharePoint list. The API also has support for querying list metadata and the list of lists.

Known to work with: SharePoint 2007, SharePoint 2013 and SharePoint online (experimental).

Usage Instructions

Installation

Download the WSDL file for the SharePoint Lists you want to interact with. This can normally be obtained at: sharepoint.url/subsite/_vti_bin/Lists.asmx?WSDL

If you are using composer, just add thybag/php-sharepoint-lists-api to your composer.json and run composer.

{
    "require": {
        "thybag/php-sharepoint-lists-api": "dev-master"
    }
}

If you are not using composer you can download a copy of the SharePointAPI files manually and include the top "SharePointAPI.php" class in your project.

Creating SharePointAPI object

In order to use the PHP SharePoint Lists API you will need a valid user/service account with the permissions to the required list.

For most SharePoint installations, you can create a new instance of the API using:

use Thybag\SharePointAPI;
$sp = new SharePointAPI('<username>', '<password>', '<path_to_WSDL>');

If your installation requires NTLM Authentication, you can instead use:

use Thybag\SharePointAPI;
$sp = new SharePointAPI('<username>', '<password>', '<path_to_WSDL>', 'NTLM');

SharePoint Online users must use:

use Thybag\SharePointAPI;
$sp = new SharePointAPI('<username>', '<password>', '<path_to_WSDL>', 'SPONLINE');

All methods return an Array by default. SetReturnType can be used to specify that results should be returned as objects instead.

Reading from a List.

To return all items from a list use either
$sp->read('<list_name>'); 

or

$sp->query('<list_name>')->get();
To return only the first 10 items from a list use:
$sp->read('<list_name>', 10); 

or

$sp->query('<list_name>')->limit(10)->get();
To return all the items from a list where surname is smith use:
$sp->read('<list_name>', NULL, array('surname'=>'smith')); 

or

$sp->query('<list_name>')->where('surname', '=', 'smith')->get();
To return the first 5 items where the surname is smith and the age is 40
$sp->read('<list_name>', 5, array('surname'=>'smith','age'=>40)); 

or

$sp->query('<list_name>')->where('surname', '=', 'smith')->and_where('age', '=', '40')->limit(5)->get();
To return the first 10 items where the surname is "smith" using a particular view, call: (It appears views can only be referenced by their GUID)
$sp->read('<list_name>', 10, array('surname'=>'smith','age'=>40),'{0FAKE-GUID001-1001001-10001}'); 

or

 $sp->query('<list_name>')->where('surname', '=', 'smith')->and_where('age', '=', '40')->limit(10)->using('{0FAKE-GUID001-1001001-10001}')->get();
To return the first 10 items where the surname is smith, ordered by age use:
$sp->read('<list_name>', 10, array('surname'=>'smith'), NULL, array('age' => 'desc')); 

or

$sp->query('<list_name>')->where('surname', '=', 'smith')->limit(10)->sort('age','DESC')->get();
To return the first 5 items, including the columns "favroite_cake" and "favorite animal"
$sp->read('<list_name>', 5, NULL, array("favroite_cake", "favorite_animal")); 

or

$sp->query('<list_name>')->fields(array("favroite_cake", "favorite_animal")->limit(5)->get();

By default list item's are returned as arrays with lower case index's. If you would prefer the results to return as object's, before invoking any read operations use:

$sp->setReturnType('object'); 

Automatically making the attribute names lowercase can also be deactivated by using:

$sp->lowercaseIndexs(FALSE);

Querying a list

The query method can be used when you need to specify a query that is to complex to be easily defined using the read methods. Queries are constructed using a number of (hopefully expressive) pseudo SQL methods.

If you for example wanted to query a list of pets and return all dogs below the age of 5 (sorted by age) you could use.

$sp->query('list of pets')->where('type','=','dog')->and_where('age','<','5')->sort('age','ASC')->get();

If you wanted to get the first 10 pets that were either cats or hamsters you could use:

$sp->query('list of pets')->where('type','=','cat')->or_where('type','=','hamster')->limit(10)->get();

If you need to return 5 items, but including all fields contained in a list, you can use. (pass false to all_fields to include hidden fields).

$sp->query('list of pets')->all_fields()->get();

If you have a set of CAML for a specific advanced query you would like to run, you can pass it to the query object using:

$sp->query('list of pets')->raw_where('<Eq><FieldRef Name="Title" /><Value Type="Text">Hello World</Value></Eq>')->limit(10)->get();

Adding to a list

To add a new item to a list you can use either the method "write", "add" or "insert" (all function identically). Creating a new record in a List with the columns forename, surname, age and phone may look like:

$sp->write('<list_name>', array('forename'=>'Bob','surname' =>'Smith', 'age'=>40, 'phone'=>'(00000) 000000' ));

You can also run multiple write operations together by using:

$sp->writeMultiple('<list_name>', array(
	array('forename' => 'James'),
	array('forename' => 'Steve')
));

Editing Rows

To edit a row you need to have its ID. Assuming the above row had the ID 5, we could change Bob's name to James with:

$sp->update('<list_name>','5', array('forename'=>'James'));

As with the write method you can also run multiple update operations together by using:

$sp->updateMultiple('<list_name>', array(
	array('ID'=>5,'job'=>'Intern'),
	array('ID'=>6,'job'=>'Intern')
));

When using updateMultiple every item MUST have an ID.

This method returns the row that has been updated. It does not always return the updated data, as SharePoint can take longer to update than this method takes to run. It is therefore not recommended to use this as a check to ensure a successful update.

Deleting Rows

In order to delete a row, an ID as well as list name is required. To remove the record for James with the ID 5 you would use:

$sp->delete('<list_name>', '5');

If you wished to delete a number of records at once, an array of ID's can also be passed to the delete multiple method

$sp->deleteMultiple('<list_name>', array('6','7','8'));

CRUD - Create, Read, Update and Delete

The above actions can also be performed using the CRUD wrapper on a list. This may be useful when you want to perform multiple actions on the same list. Crud methods do not require a list name to be passed in.

$list = $sp->CRUD('<list_name>');
$list->read(10);
$list->create(array( 'id'=>1, 'name'=>'Fred' ));

List all Lists.

You can get a full listing of all available lists within the connected SharePoint subsite by calling:

$sp->getLists();

List metaData.

You can access a lists meta data (Column configuration for example) by calling

$sp->readListMeta('My List');

By default the method will attempt to strip out non-useful columns from the results, but keep "hidden". If you'd like the full results to be returned call:

$sp->readListMeta('My List',FALSE);

You can also now ignore "hidden" columns:

$sp->readListMeta('My List', FALSE, TRUE);

Field history / versions.

If your list is versioned in SharePoint, you can read the versions for a specific field using:

$sp->getVersions('<list>', '<id>', '<field_name>');

Attach a file to a SharePoint list item

Files can be attached to SharePoint list items using:

$sp->addAttachment('<list>', '<id>', '<path_to_file>');

Helper methods

The PHP SharePoint API contains a number of helper methods to make it easier to ensure certain values are in the correct format for some of SharePoints special data types.

dateTime

The dataTime method can either be passed a text based date

 $date = \Thybag\SharepointApi::dateTime("2012-12-21");

Or a unix timestamp

$date = \Thybag\SharepointApi::dateTime(time(), true);

And will return a value which can be stored in to SharePoints DateTime fields without issue.

Lookup

The lookup data type in SharePoint is for fields that reference a row in another list. In order to correctly populate these values you will need to know the ID of the row the value needs to reference.

$value = \Thybag\SharepointApi::lookup('3','Pepperoni Pizza');

If you do not know the name/title of the value you are storing the method will work fine with just an ID (which SharePoint will also accept directly)

$value = \Thybag\SharepointApi::lookup('3');
Magic Lookup

If you are attempting to store a value in a "lookup" data type but for some reason only know the title/name of the item, not its ID, you can use the MagicLookup method to quickly look this value up and return it for you. This method will need to be passed both the items title & the list it is contained within.

$sp->magicLookup("Pepperoni Pizza", "Pizza List");

Trouble shooting

  • Unable to find the wrapper "https"

If you are getting this error it normally means that php_openssl (needed to curl https urls) is not enabled on your webserver. With many local websevers (such as XAMPP) you can simply open your php.ini file and uncomment the php_openssl line (ie. remove the ; before it).

Note: If you are using SharePoint Online and having SSL errors, please pull the latest version which has changed from SSL v3 to TLS for sharepoint online connections -

Add this line to your composer.json file.

 "thybag/php-sharepoint-lists-api": "dev-develop"
Comments
  • Wrong version exception

    Wrong version exception

    I have updated to the most recent SharePointAPI.php, and I am getting the following error:

    PHP Fatal error: Uncaught exception 'Exception' with message 'Error (VersionMismatch) Wrong Version,more=' in /usr/local/bin/SharePointAPI.php:835 Stack trace: #0 /usr/local/bin/SharePointAPI.php(461): SharePointAPI->onError(Object(SoapFault)) #1 /usr/local/bin/upload_providers.php(109): SharePointAPI->read('{387DF9C7-7389-...', NULL, Object(SPQueryObj)) #2 {main}

    thrown in /usr/local/bin/SharePointAPI.php on line 835

    I am using SharePoint 2010

    opened by colleenatrsc 14
  • "Looks like we got no XML document"

    I had successfully implemented your API and have been using it for months. Then yesterday morning it had mysteriously stopped working. I checked the response in my Network tab and it says

    "Looks like we got no XML document"

    I don't believe I changed anything. I began debugging and dumped the response form the Authentication in the SharePointOnlineAuth.php __doRequest function. It displayed:

    "403 Forbidden".

    Is the "403 Forbidden" valid and they're now rejecting my authentication request?

    I checked all the parameters being passed to the __doRequest function and $location was incorrect. I have the WSDL file URL as:

    "https://mysharepointsite............/Lists.asmx?WSDL"

    Which displays the XML correctly when going directly to the URL. But when I output $location it is missing the "?WSDL" query string. If I manually append it inside the function, the dump of $response contains the XML from the WSDL file. If I remove the dump the error in my Network tab now says "Error (VersionMismatch) Wrong Version".

    I've tried setting SOAP version to SOAP_1_2 but no luck there.

    Should the $location variable contain the querystring?

    I'm using the "SPONLINE" authentication mode. Can you confirm the API still works for this and that Microsoft didn't break your code by changing something on their end in the last 2 days?

    Please help.

    opened by ghost 13
  • Dependency to NTLM proxy?

    Dependency to NTLM proxy?

    opened by kasperg 13
  • The security validation for this page is invalid.

    The security validation for this page is invalid.

    Hi,

    I tried to create sharepointlist to store candidate information. I encount the "The security validation for this page is invalid." while attach the file. I am trying first time in php. I couldn't trace the issue. This is my code. $sp->addAttachment('applicant', 18, "files/PID.txt");

    How do I resolve this issue? is there any syntax error in the code which I provided. thanks

    opened by tnsankar 9
  • Office365 / SharePoint Online support

    Office365 / SharePoint Online support

    Please add support for SharePoint Online. It appears that to use SP Online, you need to use Claims based authentication.

    I found some info on how to do this here; http://allthatjs.com/2012/03/28/remote-authentication-in-sharepoint-online/

    If you need access to a SharePoint Online account to test, please let me know and I will try and get you access.

    opened by nesl247 9
  • Missing Fields

    Missing Fields

    Love it, however when I do a get() or query() not all the fields will be returned. I know they exist and they can be interacted with because I am able to do an update or insert action. At first I thought it was only field types with multiple lines of text (that was the first type I noticed) but there does not appear to be any pattern associated with the field type (the multiple lines of text's are all set to plain text just in case you were curious). I have quite a few fields that I have defined (~70+).

    opened by Tukachinchilla 7
  • Versioning

    Versioning

    Hello -

    I am happy to look into this, but before I put forth effort I wanted to check to see if you have experienced this... I am needing to try to use the API to read an older version of an item on a sharepoint list.

    Example: Someone creates a record (first version), then they updated it, we now have a second version in versioning history. I need to compare the two in PHP.

    Do you know if this is possible?

    Thanks,

    Tim

    new feature 
    opened by BinaryZeph 7
  • Character encoding problems

    Character encoding problems

    Our script, API and Sharepoint online are using UTF-8 encoding but a Czech special characters are not transferred to Sharepoint via API write function. Does someone have any idea how to solve that?

    Thanks a lot

    Awaiting user 
    opened by pavelkucera00 6
  • CURLOPT_CERTINFO should be long not string

    CURLOPT_CERTINFO should be long not string

    Having a problem with possibly the server config on a remote DEV server. Although the code works on my local DEV environment (macports LAMP stack), it gives this error on remote DEV server.

    Warning: curl_setopt() expects parameter 2 to be long, string given in SoapClientAuth->__doRequest() (line 110 of /var/www/html/sites/all/modules/custom/sharepoint/helper/SoapClientAuth.php).
    
    Notice: Use of undefined constant CURLOPT_CERTINFO - assumed 'CURLOPT_CERTINFO' in SoapClientAuth->__doRequest() (line 110 of/var/www/html/sites/all/modules/custom/sharepoint/helper/SoapClientAuth.php).
    

    CURLOPT_CERTINFO should be long not string CURLOPT_CERTINFO = 172 on my local.

    opened by msusol 6
  • Or and Other Qualifiers?

    Or and Other Qualifiers?

    Has there been any thought put into a function to pull more than "And", and "Eq"? I worked on a snippet to allow the other comparisons, but have not sorted out how to easily implement "" into the where clause.

    Before I put much more work into it, I just wondered if you had already.

    Thanks,

    Tim

    opened by BinaryZeph 6
  • Error when trying to create a list item

    Error when trying to create a list item

    I can correctly retreive lists and their items, but when I try to add a new item to the list I get the following error log.

    I am working with a Sharepoint Online site

    2016/05/24 14:27:03 [error] 9615#9615: *49 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught exception 'Exception' with message 'Error (soap:Client) Server did not recognize the value of HTTP Header SOAPAction: http://schemas.microsoft.com/sharepoint/soap/UpdateListItems", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems.,more=' in /home/erik/code/Hoppinger/sncu/vendor/thybag/php-sharepoint-lists-api/src/Thybag/SharePointAPI.php:1015
    Stack trace:
    #0 /home/erik/code/Hoppinger/sncu/vendor/thybag/php-sharepoint-lists-api/src/Thybag/SharePointAPI.php(958): Thybag\SharePointAPI->onError(Object(SoapFault))
    #1 /home/erik/code/Hoppinger/sncu/vendor/thybag/php-sharepoint-lists-api/src/Thybag/SharePointAPI.php(509): Thybag\SharePointAPI->modifyList('Meldingen', Array, 'New')
    #2 /home/erik/code/Hoppinger/sncu/vendor/thybag/php-sharepoint-lists-api/src/Thybag/SharePointAPI.php(480): Thybag\SharePointAPI->writeMultiple('Meldingen', Array)
    

    I'm kinda lost where this comes from, but could it be that it has to do with the following part? https://github.com/thybag/PHP-SharePoint-Lists-API/blob/develop/src/Thybag/Auth/SharePointOnlineAuth.php#L46

    opened by EDeijl 4
  • PHP 8.1: $this->_login and $this->_password not accessible

    PHP 8.1: $this->_login and $this->_password not accessible

    When #177 is fixed, the next problem appears:

    PHP Warning: Undefined property: Thybag\Auth\SharePointOnlineAuth::$_login in vendor/thybag/php-sharepoint-lists-api/src/Thybag/Auth/SharePointOnlineAuth.php on line 78 Warning: Undefined property: Thybag\Auth\SharePointOnlineAuth::$_password in vendor/thybag/php-sharepoint-lists-api/src/Thybag/Auth/SharePointOnlineAuth.php on line 79

    This is because at least in PHP 8.1, _login and _password are private, and the child class cannot access this anymore.

    A backwards-compatible workaround for this problem would be to catch the options in a custom constructor, and using them later.

    opened by cweiske 0
  • Missing return type for SoapClientAuth::__doRequest (PHP 8.1.x)

    Missing return type for SoapClientAuth::__doRequest (PHP 8.1.x)

    please add the return type "?string" for the method SoapClientAuth::__doRequest because it leads to an error like

    Deprecated: Return type of Thybag\Auth\SoapClientAuth::__doRequest($request, $location, $action, $version, $one_way = 0)
    should either be compatible with SoapClient::__doRequest(string $request, string $location, string $action, int $version, bool $oneWay = false): ?string,
    or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in ~\vendor\thybag\php-sharepoint-lists-api\src\Thybag\Auth\SoapClientAuth.php on line 84
    
    public function __doRequest($request, $location, $action, $version, $one_way = 0):?string
    
    opened by ReneGercken 0
  • Error in Authentication

    Error in Authentication

    I am getting this error when I am trying to read a list. I am reading from a SharePoint Online List.

    This used to work earlier, but I am getting this error now. Don't know what is wrong. image

    opened by mrinmaisharma 0
  • Function write(), nothing is happening. What parameters is needed ?

    Function write(), nothing is happening. What parameters is needed ?

    Hi all,

    Thanks you for this API, i needed an API for my laravel website and you answered my request.

    I've just a problem to create a folder or a file. My list in 'Documents' is a list of document (Document's name : "A1"), and when i want create an object i do : $sp->write('Documents',array('Title'=>'TEST API', 'id'=> '4')); , nothing is happening.

    I don't understand what parameters i need to put on function write() for create a folder.

    opened by Jedguy 1
  • Write in document library

    Write in document library

    Hey,

    first of all thank you for this project. I use it to read and add row in list and it works great. But now I need to add a row in a document library. It's possible with your project ? Have you ever doing that?

    opened by Giudice 2
Releases(0.7.2)
Owner
Carl Saggs
A full stack web developer
Carl Saggs
It's a PHP Application to simplify working with Google Sheets SDK for php.

About GoogleSheetsPHP It's a PHP Application to simplify working with Google Sheets SDK for php. Note: i used Slim 3 to construct the application but

Sami Alateya 5 Dec 20, 2022
It’s a bot using simple feature - jangan keseringan make (haram cok)

It’s a bot using simple feature - jangan keseringan make (haram cok)

null 2 Jan 26, 2022
It’s a bot using simple feature - jangan keseringan make (haram cok)

Indodax-machine It’s a bot using simple feature - jangan keseringan make (haram cok) Example of Request PHP (API-PANAS) Get Info Sample code below : <

null 2 Jan 26, 2022
PHP package providing easy and fast access to Twitter API V2.

Twitter API V2 is a PHP package that provides an easy and fast access to Twitter REST API for Version 2 endpoints.

Julien SCHMITT 38 Dec 12, 2022
HTTP Requestor: Package for a client request that supports you to make an external service request easily and with fast usage.

HttpRequestor from Patienceman HTTP Requestor: Package for a client request that supports you to make an external service request easily and with fast

Manirabona Patience 2 Aug 26, 2022
Easy to install email tracker with gui and telegram api bot with date device & ip tracking,

mail-php-tracking-with-gui ?? Simple mail tracking program that uses php, html, telegram bot, and a gui The gui The gui lets you create specific links

null 7 Dec 20, 2022
This package is a simple API laravel wrapper for Pokemontcg with a sleek Model design for API routes and authentication.

This package is a simple API laravel wrapper for Pokemontcg with a sleek Model design for API routes and authentication.

Daniel Henze 3 Aug 29, 2022
TeleBot - Easy way to create Telegram-bots in PHP. Rich Laravel support out of the box.

TeleBot is a PHP library for telegram bots development. Rich Laravel support out of the box. Has an easy, clean, and extendable way to handle telegram Updates.

WeStacks 206 Jan 6, 2023
Toxiproxy PHP Client - Toxiproxy makes it easy and trivial to test network conditions, for example low-bandwidth and high-latency situations

Toxiproxy makes it easy and trivial to test network conditions, for example low-bandwidth and high-latency situations. toxiproxy-php-client includes everything needed to get started with configuring Toxiproxy upstream connection and listen endpoints.

Adrian Parker 29 Jun 24, 2022
The Smart-ID PHP client can be used for easy integration of the Smart-ID solution to information systems or e-services

Smart-ID PHP client Introduction The Smart-ID PHP client can be used for easy integration of the Smart-ID solution to information systems or e-service

SK ID Solutions 16 Oct 23, 2022
Nexmo REST API client for PHP. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.

Client Library for PHP Support Notice This library and it's associated packages, nexmo/client and nexmo/client-core have transitioned into a "Maintena

Nexmo 75 Sep 23, 2022
OpenAI API Client is a component-oriented, extensible client library for the OpenAI API. It's designed to be faster and more memory efficient than traditional PHP libraries.

OpenAI API Client in PHP (community-maintained) This library is a component-oriented, extensible client library for the OpenAI API. It's designed to b

Mounir R'Quiba 6 Jun 14, 2023
A simple PHP GitHub API client, Object Oriented, tested and documented.

PHP GitHub API A simple Object Oriented wrapper for GitHub API, written with PHP. Uses GitHub API v3 & supports GitHub API v4. The object API (v3) is

KNP Labs 2k Jan 7, 2023
A simple Object Oriented PHP Client for Termii SMS API

Termii Client A simple Object Oriented PHP Client for Termii SMS API. Uses Termii API. Requirements PHP >= 7.2 Guzzlehttp ~6|~7 Installation Via Compo

Ilesanmi Olawale Adedotun 5 Feb 24, 2022
Simple Curl based wrapper for Binance API for PHP scripts

Simple Curl based wrapper for Binance API for PHP scripts Feaures API support for SPOT data/trading FAPI/DAPI support for futures data/trading Curl-on

Mr Crypster 22 May 1, 2022
Telegram API made for php (Simple usage)

Telegram Telegram API made for php (Simple usage) How to use? Download the project & place Telegram folder tp your project directory (For example i se

null 0 Apr 4, 2022
Super-simple, minimum abstraction MailChimp API v3 wrapper, in PHP

MailChimp API Super-simple, minimum abstraction MailChimp API v3 wrapper, in PHP. I hate complex wrappers. This lets you get from the MailChimp API do

Drew McLellan 2k Dec 22, 2022
Just a simple API PHP library with basic functions and config.

Installation Clone this Repository in your PHP Project git clone https://github.com/maximilianosinski/simple-api-php-library.git Change your Project n

Maximilian Osinski 1 May 9, 2022
Implementation of a library to process SISP vinti4 payment in a easy way.

Implementation of a library to process SISP vinti4 payment in a easy way.

Faxi 6 Nov 3, 2022