Skip to content

Example calls

Caitlin Bales (MSFT) edited this page Oct 25, 2016 · 4 revisions

Usage Examples

Set custom request data

  $graph = new Graph();
  $graph
	  ->setBaseUrl("https://graph.microsoft.com/")
	  ->setApiVersion("beta")
	  ->setAccessToken($_SESSION['access_token']);

  $user = $graph->createRequest("get", "/me")
			    ->addHeaders(array("Content-Type" => "application/json"))
			    ->setReturnType("User")
			    ->setTimeout("1000")
			    ->execute();

Get a collection of items

$docGrabber = $graph->createCollectionRequest("GET", "/me/drive/root/children")
			        ->setReturnType("DriveItem")
			        ->setPageSize(2);
$docs = $docGrabber->getPage();

foreach ($docs as $doc){
	$docArray[] = $doc->getName();
}

Send an email

$mailBody = array( "Message" => array(
                   "subject" => "Test Email",
                   "body" => array(
                       "contentType" => "html",
                       "content" => DUMMY_EMAIL
                   ),
                 "sender" => array(
                     "emailAddress" => array(
                         "name" => $name,
                         "address" => $email
                     )
                 ),
                 "from" => array(
                     "emailAddress" => array(
                             "name" => $name,
                             "address" => $email
                     )
                 ),
                 "toRecipients" => array(
                     array(
                       "emailAddress" => array(
                           "name" => $name,
                           "address" => $email
                       
                  	)
                 )
              )
          )
   );

$graph->createRequest("POST", "/me/sendMail")
	  ->attachBody($mailBody)
	  ->execute();

Download an item

$graph->createRequest("GET", "/me/drive/items/{id}/content")
	  ->download('C:/dump.docx');

Upload an item

$graph->createRequest("PUT", "/me/drive/root/children/copydoc.docx/content")
	  ->upload('C:/copydoc.docx');
Clone this wiki locally