Microsoft Teams – Microsoft Graph API to return JSON with meetingURL – PHP

At our company, we are trying to implement this script so we can call a page and get in return a JSON file with a teams meeting url generated everytime we call it.

We allways get this error:

Fatal error: Uncaught MicrosoftGraphGeneratedModelsODataErrorsODataError in C:xampphtdocsteamsapivendormicrosoftmicrosoft-graphsrcGeneratedModelsODataErrorsODataError.php:36 Stack trace: #0 C:xampphtdocsteamsapivendormicrosoftkiota-serialization-jsonsrcJsonParseNode.php(108): MicrosoftGraphGeneratedModelsODataErrorsODataError::createFromDiscriminatorValue(Object(MicrosoftKiotaSerializationJsonJsonParseNode)) #1 C:xampphtdocsteamsapivendormicrosoftkiota-http-guzzlesrcGuzzleRequestAdapter.php(666): MicrosoftKiotaSerializationJsonJsonParseNode->getObjectValue(Array) #2 C:xampphtdocsteamsapivendormicrosoftkiota-http-guzzlesrcGuzzleRequestAdapter.php(160): MicrosoftKiotaHttpGuzzleRequestAdapter->throwFailedResponse(Object(GuzzleHttpPsr7Response), Array, Object(OpenTelemetryAPITraceNonRecordingSpan)) #3 C:xampphtdocsteamsapivendorphp-httppromisesrcFulfilledPromise.php(39): MicrosoftKiotaHttpGuzzleRequestAdapter->MicrosoftKiotaHttp{closure}(Object(GuzzleH in C:xampphtdocsteamsapivendormicrosoftmicrosoft-graphsrcGeneratedModelsODataErrorsODataError.php on line 36

  1. We created the App on Azure, as a “Entreprise App” (Tested just App Registrations also, didn’t work also) — Created with Admin account;
  2. Added this permissions: Calendars.ReadWrite, Mail.ReadWrite, OnlineMeetings.ReadWrite.All, User.Read, User.ReadWrite.All, VirtualEvent.Read.All (Granted Admin Consent);
  3. Added Single-page applications redirect url: http://localhost/teamspai/index.php
  4. Tested as Multitenant and Singletenant – not working both options;
  5. Added Access using Powershell: New-CsApplicationAccessPolicy.. to the AppId and then Grant-CsApplicationAccessPolicy .. -Global;

We just need to return a JSON with the URL for the meeting.

Our code:

<?php 
include_once('vendor/autoload.php');
use MicrosoftGraphGraphServiceClient;
use MicrosoftKiotaAbstractionsApiException;
use MicrosoftKiotaAuthenticationOauthClientCredentialContext;
use MicrosoftGraphGeneratedModelsOnlineMeeting;


$scopes = ['https://graph.microsoft.com/.default'];
$tenantId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$clientId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
 
$tokenRequestContext = new ClientCredentialContext(
    $tenantId,
    $clientId,
    $clientSecret
);

$graphServiceClient = new GraphServiceClient($tokenRequestContext);
$requestBody = new OnlineMeeting(); 
$result = $graphServiceClient->me()->onlineMeetings()->post($requestBody)->wait();
echo json_encode($result);
?>

Hope someone can help us!

I tried:

  • Add Permissions
  • Single Tenant
  • Multi Tenant
  • Access Policy
  • Downgrade MSGraph
  • Created new App