Search code examples
microsoft-graph-apimicrosoft-graph-calendar

Microsoft Graph findMeetingTimes - 401 UnknownError


I have registered an application in Azure Active Directory to call findMeetingTimes from Microsoft Graph. I am able to successfully authorize, get a token, and make other Graph API calls, but receive a 401 - Unauthorized response with an error code of "UnknownError" for the endpoint https://graph.microsoft.com/v1.0/me/findMeetingTimes.

I am using a Microsoft work account for these activities, and I am able to login with said account and view the calendar. I have tried other calendar-related API calls including /me/calendar/getSchedule and /me/events and received successful responses. I am mostly testing with Postman, but have attempted to use the Graph Explorer and gotten the same response.

I have also checked that the token I am using contains the correct scope of both Calendars.Read.Shared and Calendars.ReadWrite.Shared. I originally tried with just the scope of Calendars.Read.Shared, but to no avail.

This is the response I receive when requesting a token:

{
    "token_type": "Bearer",
    "scope": "Calendars.Read.Shared Calendars.ReadWrite.Shared User.Read profile openid email",
    "expires_in": 3600,
    "ext_expires_in": 3600,
    "access_token": "foo",
    "refresh_token": "bar"
}

The request I make (with an empty body, as all body parameters are optional):

POST /v1.0/me/findMeetingTimes HTTP/1.1
Host: graph.microsoft.com
Content-Type: application/json
Authorization: Bearer foo

The 401 response I receive:

{
    "error": {
        "code": "UnknownError",
        "message": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"/>\r\n<title>401 - Unauthorized: Access is denied due to invalid credentials.</title>\r\n<style type=\"text/css\">\r\n<!--\r\nbody{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}\r\nfieldset{padding:0 15px 10px 15px;} \r\nh1{font-size:2.4em;margin:0;color:#FFF;}\r\nh2{font-size:1.7em;margin:0;color:#CC0000;} \r\nh3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} \r\n#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:\"trebuchet MS\", Verdana, sans-serif;color:#FFF;\r\nbackground-color:#555555;}\r\n#content{margin:0 0 0 2%;position:relative;}\r\n.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}\r\n-->\r\n</style>\r\n</head>\r\n<body>\r\n<div id=\"header\"><h1>Server Error</h1></div>\r\n<div id=\"content\">\r\n <div class=\"content-container\"><fieldset>\r\n  <h2>401 - Unauthorized: Access is denied due to invalid credentials.</h2>\r\n  <h3>You do not have permission to view this directory or page using the credentials that you supplied.</h3>\r\n </fieldset></div>\r\n</div>\r\n</body>\r\n</html>\r\n",
        "innerError": {
            "request-id": "foo",
            "date": "2019-06-21T13:52:00"
        }
    }
}

Is there any other configuration that I can change to get around this issue?


Solution

  • We've managed to track down the issue: the O365 tenant I was attempting to make the API call on was a Government tenant and did not have the "findMeetingTimes" function enabled/installed within the tenant.

    The workaround for the time being for us is to use the Outlook REST API, which has a similar function: https://learn.microsoft.com/en-us/previous-versions/office/office-365-api/api/version-2.0/calendar-rest-operations#FindMeetingTimes