1
votes

Please do not report as duplicate because all other topics have not solved my issue, thanks.

I'm using Microsoft Graph API to list and create calendar events, however, I can't seem to make the findMeetingTimes endpoint work.

This is my authorization URL:

https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize
  ?client_id=xxxxx
  &response_type=code
  &redirect_uri=xxxxx
  &response_mode=form_post
  &scope=openid profile User.ReadWrite User.ReadBasic.All Sites.ReadWrite.All Contacts.ReadWrite People.Read Notes.ReadWrite.All Tasks.ReadWrite Mail.ReadWrite Files.ReadWrite.All Calendars.ReadWrite
  &state=12345

Then I request an access token using the same scopes:

$request = json_decode($guzzle->post('https://login.microsoftonline.com/common/oauth2/v2.0/token', [
    'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],
    'form_params' => [
        'client_id' => 'xxxxx',
        'scope' => 'openid profile User.ReadWrite User.ReadBasic.All Sites.ReadWrite.All Contacts.ReadWrite People.Read Notes.ReadWrite.All Tasks.ReadWrite Mail.ReadWrite Files.ReadWrite.All Calendars.ReadWrite',
        'code' => $auth_code,
        'grant_type' => 'authorization_code',
        'redirect_uri' => 'xxxxx',
        'client_secret' => 'xxxxx'
    ],
])->getBody()->getContents());

After that I'm trying the findMeetingTimes endpoint using:

$request = json_decode($guzzle->post('https://graph.microsoft.com/v1.0/me/findMeetingTimes', [
    'headers' => [
        'Authorization' => 'Bearer ' . $accessToken,
        'Content-Type' => 'application/json',
    ],
    'body' => '{
        "attendees": [
        {
            "type": "required",
            "emailAddress": {
            "name": "My Name",
            "address": "[email protected]"
            }
        }
        ],
        "timeConstraint": {
        "activityDomain":"work",
        "timeslots": [
            {
            "start": {
                "dateTime": "2019-04-02T09:00:00",
                "timeZone": "Pacific Standard Time"
            },
            "end": {
                "dateTime": "2019-04-03T17:00:00",
                "timeZone": "Pacific Standard Time"
            }
            }
        ]
        }
    }',
    ])->getBody()->getContents());

However, it keeps returning:

401 - Unauthorized: Access is denied due to invalid credentials.

You do not have permission to view this directory or page using the credentials that you supplied.

Does anyone know what I'm missing? Note that I'm not using a Microsoft work/school account, just my regular one. (Does it matter?)

1
is your redirect url in http:// or https://iamawesome
graph only redirect to https;//iamawesome
I'm using Ngrok, with Https. @iamawesomeTim Hef

1 Answers

2
votes

Its not possible to call this endpoint with personal accounts, this is metioned very cleary in the documentation

enter image description here