Add outlook meeting using MS graph and msgraph-sdk-php

(Andy) Dragos Comanescu 1 Reputation point
2022-02-03T14:28:24.703+00:00

Hi
I need to create a meeting in outlook from a third party PHP system using the msgraph-sdk-php.
So far I can't even read my own user info, let alone create that meeting.

Please advise what permission does one need to create that meeting and what is the call please.
Here is my basic name call that returns a valid token, but then just a blank screen.

$url = 'https://login.microsoftonline.com/' . $tenantId . '/oauth2/token?api-version=1.0';
$token = json_decode($guzzle->post($url, [
'form_params' => [
'client_id' => $clientId,
'client_secret' => $clientSecret,
'resource' => 'https://graph.microsoft.com/',
'grant_type' => 'client_credentials',
],
])->getBody()->getContents());
$ms_accessToken = $token->access_token;

$url = 'https://login.microsoftonline.com/' . $tenantId . '/oauth2/token?api-version=1.0';

$token = json_decode($guzzle->post($url, [
'form_params' => [
'client_id' => $clientId,
'client_secret' => $clientSecret,MS Graph with msgraph-sdk-php
'resource' => 'https://graph.microsoft.com/',
'grant_type' => 'client_credentials',
],
])->getBody()->getContents());
$ms_accessToken = $token->access_token;

echo '$accessToken: ' . $ms_accessToken ;

use Microsoft\Graph\Graph;
use Microsoft\Graph\Model;

$graph = new Graph();

$graph->setBaseUrl("https://graph.microsoft.com/")
->setApiVersion("beta")
->setAccessToken($ms_accessToken);

$user = $graph->createRequest("get", "/users/[my_user_email]")
->addHeaders(array("Content-Type" => "application/json"))
->setReturnType(Model\User::class)
->setTimeout("1000")
->execute();

$u = $user->getDisplayName();

echo '<br>user: ' . $u;

Microsoft Security Microsoft Graph
{count} votes

1 answer

Sort by: Most helpful
  1. JanardhanaVedham-MSFT 3,566 Reputation points
    2022-02-04T13:08:51.963+00:00

    Hi @(Andy) Dragos Comanescu ,

    You can use below Microsoft Graph Calendar Events API to create the outlook events or meetings and "Calendars.ReadWrite" delegated /application permissions need to be granted to your application.

    POST https://graph.microsoft.com/v1.0/me/events  
    POST https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/events  
    

    Note : Calling the /me endpoint requires a signed-in user and therefore a delegated permission. Application permissions are not supported when using the /me endpoint.

    Please refer this Create a new event using Microsoft Graph API in PHP web app documentation which is very relevent to your requirement. Also, You can also refer this microsoft documented tutorial on how to build a PHP web app that uses the Microsoft Graph API to retrieve calendar information for a user.

    Below is the documentation on how to create and enable an event as an online meeting using Microsoft Graph Calendar / Events API :

    https://learn.microsoft.com/en-us/graph/api/user-post-events?view=graph-rest-1.0&tabs=http#example-4-create-and-enable-an-event-as-an-online-meeting

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have any further questions about this answer, please click "Comment".

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.