Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to connect sharepoint with php

Do anyone know how to integrate Sharepoint and Php. I am trying to develop php app which can connect to Sharepoint.In particular since basically I am website developer, I want my all websites to be connected with Sharepoint. So, simply I want to create Php app such that it works for all the websites. I don't know is it possible or not but I want to give it a try but don't know how to proceed.

Any idea/suggestions is welcome.

Thanks in advance.

like image 737
samjhana joshi Avatar asked Jul 09 '13 10:07

samjhana joshi


3 Answers

Try this API

In SharePoint

Download the WSDL. Usually at this location: <sharepoint.url>/subsite/_vti_bin/Lists.asmx?WSDL

Download the API

Make sure to save both SoapClientAuth.php and SharePointAPI.php

In PHP

// 0: include api in your php script.
require_once('SharePointAPI.php');

// 1: connect to SharePoint
$sp = new SharePointAPI('<username>', '<password>', '<path_to_WSDL>');

// 2: read a list
$listContents = $sp->read('<list_name>'); 

// 3: now you have a 2-D array to work with in PHP
foreach($listContents as $item)
{
    var_dump($item);
}

With this API, you can also query, update, create, delete lists, query list metadata

like image 72
NoodleFolk Avatar answered Sep 21 '22 02:09

NoodleFolk


I have used this in API to connect my PHP web application with SharePoint and transferring data From PHP to SharePoint, it worked 100% for me:

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 SharePoint API 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('', '', '');

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

    use Thybag\SharePointAPI;
    $sp = new SharePointAPI('', '', '', 'NTLM');

SharePoint Online users must use:

    use Thybag\SharePointAPI;
    $sp = new SharePointAPI('', '', '', '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('');
or
    $sp->query('')->get();

To return only the first 10 items from a list use:

    $sp->read('', 10);

or

    $sp->query('')->limit(10)->get();

To return all the items from a list where surname is smith use:

    $sp->read('', NULL, array('surname'=>'smith'));

or

    $sp->query('')->where('surname', '=', 'smith')->get();

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','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('Hello World')->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('', array('forename'=>'Bob','surname' =>'Smith', 'age'=>40, 'phone'=>'(00000) 000000' ));

You can also run multiple write operations together by using:

    $sp->writeMultiple('', 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('','5', array('forename'=>'James'));/code>

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

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

When using updateMultiple every item MUST have an ID.

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('', '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 methods

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

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 SharePoint special data types.

dateTime The DateTime 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);

Troubleshooting

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 web server. With many local web servers (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

You can perform CRUD (Create/Read/Update/Delete) operation with above SharePoint API.

Reference URL link: https://github.com/thybag/PHP-SharePoint-Lists-API

like image 35
Yogi Ghorecha Avatar answered Sep 19 '22 02:09

Yogi Ghorecha


If I read your question right, you want to interact with your SharePoint site using PHP. You can do most interaction by using SharePoint's web services. For instance, you can read all list items using the lists web service (http:///_vti_bin/lists.asmx). You can upload files to a SharePoint document library. I searched furiously for an example of what I did to accomplish that, but I have lost it. I remember using Curl to do the uploads.

There are a number of websites that discuss using PHP to access SharePoint data. Here are a couple that I found with a simple google search:

  • http://craiget.com/hello-sharepoint-meet-php/
  • http://davidsit.wordpress.com/2010/02/23/reading-a-sharepoint-list-with-php/
  • http://social.msdn.microsoft.com/Forums/sharepoint/en-US/3aa34d3d-0f0b-48bd-9752-f9c0c4577804/php-and-sharepoint-calendar-list
  • http://brian-strickland.com/index.php/2012/04/19/displaying-and-downloading-sharepoint-document-libraries-using-php/

As well as a discussion about a tool called Camelot PHP here

like image 42
Robbert Avatar answered Sep 21 '22 02:09

Robbert