Git Product home page Git Product logo

phpspo's Introduction

SharePoint client for PHP

This library provides a SharePoint client for PHP applications. This allows you to performs CRUD operations on SharePoint data, using an REST/OData based API for SharePoint 2013.

The current version is restricted to SharePoint Online, using claims based authentication.

Requirements

  • PHP 5.3 or later

API

PHP:cURL library is used to make HTTP requests to performs CRUD operations on SharePoint data, using SharePoint 2013 REST API

SPOClient(url)

An object of this class represents a REST Service client for the specified SharePoint Online (SPO) site.

Example:

$client = new SPOClient($url);

client.signIn (username, password)

The signin method performs a claims-based authentication:

  • build a SAML request (using SAML.xml template included in module)
  • submit a SAML token request to Microsoft Online Security Token Service
  • receive a signed security token
  • POST the token to SharePoint Online
  • receive FedAuth and rtFa authentication cookies
  • store the cookies in client for use in subsequent requests

Example:

try {
    $client = new SPOClient($url);
    $client->signIn($username,$password);
    echo 'You have authenticated successfully\n';
}
catch (Exception $e) {
    echo 'Connection failed: ',  $e->getMessage(), "\n";
}

The following examples demonstrates how to perform basic CRUD operations on SharePoint list data.

require_once 'SPOClient.php';


$username = '[email protected]';
$password = 'password';
$url = "https://tenant.sharepoint.com/";

generateTasks($url,$username,$password);

function generateTasks($url,$username,$password){
    $client = new SPOClient($url);
    $client->signIn($username,$password);
    $listTitle = 'Tasks';
    $list = $client->getList($listTitle);
    
    for ($i=0;$i<4;$i++) {
        $itemProperties = array('Title' => 'Order Approval ' . $i, 'Body' => 'Order approval task');
        $item = $list->addItem($itemProperties);
        print "Task '{$item->Title}' has been created succesfully.\r\n";
    }
}

How to create SharePoint list item:

function addListItem($url,$username,$password){
    $client = new SPOClient($url);
    $client->signIn($username,$password);
    $listTitle = 'Tasks';
    $list = $client->getList($listTitle);
    $itemProperties = array('Title' => 'Order Approval', 'Body' => 'Order approval task');
    $item = $list->addItem($itemProperties);
    
}

How to delete SharePoint list item:

function deleteListItem($url,$username,$password){
    $client = new SPOClient($url);
    $client->signIn($username,$password);
    $listTitle = 'Tasks';
    $list = $client->getList($listTitle);
    $list->deleteItem(2);
    
}

How to update SharePoint list item:

function updateListItem($url,$username,$password){
    $client = new SPOClient($url);
    $client->signIn($username,$password);
    $listTitle = 'Tasks';
    $list = $client->getList($listTitle);
    $itemProperties = array('PercentComplete' => 1);
    $list->updateItem(2,$itemProperties);
    
}

Changelog

1.0.0 - May 23st, 2014

  • Initial release.

phpspo's People

Contributors

vgrem avatar nkgokul avatar

Watchers

James Cloos avatar Ahmed avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.