Skip to content

Instantly share code, notes, and snippets.

@vgrem
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgrem/22d587064ab771131811 to your computer and use it in GitHub Desktop.
Save vgrem/22d587064ab771131811 to your computer and use it in GitHub Desktop.
The example demonstrates how to generate SharePoint List data from PHP application
<?php
require_once __DIR__ . '/../../Faker/src/autoload.php'; //Faker library (https://github.com/fzaninotto/Faker)
require_once 'SPOClient.php';
$username = 'username@tenant.onmicrosoft.com';
$password = 'password';
$url = "https://tenant.sharepoint.com/";
generateContacts($url,$username,$password);
function generateContacts($url,$username,$password){
$client = new SPOClient($url);
$client->signIn($username,$password);
$list = $client->getList('Contacts');
$contactsCount = 120;
for($i = 0; $i < $contactsCount; $i++){
$contactEntry = createContactEntry();
$item = $list->addItem($contactEntry);
print "Contact '{$item->Title}' has been created succesfully.\r\n";
}
}
function createContactEntry()
{
$contactCard = Faker\Factory::create();
return array('Title' => $contactCard->username,
'FullName' => $contactCard->name,
'Email' => $contactCard->email,
'Company' => $contactCard->company,
'WorkPhone' => $contactCard->phoneNumber,
'WorkAddress' => $contactCard->streetAddress,
'WorkCity' => $contactCard->city,
'WorkZip' => $contactCard->postcode,
'WorkCountry' => $contactCard->country,
'WebPage' => array ('Url' => $contactCard->url)
);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment