Forum Discussion
yhassoun
Sep 28, 2023Copper Contributor
Failing to connect to Microsoft Bookings API
I am trying to pull Microsoft Booking calendar data into my WP site. I have created the required web app and granted my user the required access and delegation to connect to the app, and gave my app...
fh_aimcom
Oct 11, 2023Copper Contributor
First of all, I can recommend the PHP package https://packagist.org/packages/microsoft/microsoft-graph for the usage of the Microsoft Graph API. It's easier than writing all the requests on yourself with Guzzle.
I'm confused that you are trying to use your username with password and a client secret at the same time. Client secrets have the advantage that you don't need to use (and therefore expose) your account password compared to a simple app token with strictly limited permissions. So you should try to get an access token with client ID, client secret, scope and grant type, for example like this:
$guzzle = new \GuzzleHttp\Client();
$url = 'https://login.microsoftonline.com/' . $tenantId . '/oauth2/v2.0/token';
$token = json_decode($guzzle->post($url, [
'form_params' => [
'client_id' => $clientId,
'client_secret' => $clientSecret,
'scope' => 'https://graph.microsoft.com/.default',
'grant_type' => 'client_credentials',
],
])->getBody()->getContents());
$accessToken = $token->access_token;