terrorfall
terrorfall

Reputation: 1121

Access denied for Room Calendar in Office 365 API

I am writing an application in PHP using the Office 365 REST API that pulls down a list of all events for a meeting room. I have authorised the application and can pull back a list of the room events by navigating to the URL through my browser, however, as soon as I try to make the request through CURL I get the following response.

{"error":{"code":"ErrorAccessDenied","message":"Access is denied. Check credentials and try again."}}

My PHP is as follows

public function getCalendarEvents($token, $calendar) {

    $url = "https://outlook.office365.com/api/v1.0/users/$calendar/events";
    //$url = "https://outlook.office365.com/api/v1.0/me/events";

    $headers = array('Authorization: Bearer ' . $token, 'Content-Type: application/json', 'Accept:application/json');

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);

    $output=curl_exec($ch);

    $info = curl_getinfo($ch);
    //print_r($info['request_header']);

    curl_close($ch);
    print_r($output);
}

I have tried passing in the email address of the room as both

$url = "https://outlook.office365.com/api/v1.0/users/[email protected]/events";

and

$url = "https://outlook.office365.com/api/v1.0/Users('[email protected]')/Events";

Neither of which work. I am able to pull back all calendar events for myself using

$url = "https://outlook.office365.com/api/v1.0/me/events";

I am an admin on the Office 365 portal, as well as being set to have full permissions on the room. In my research I came across this SO answer, but unchecking this option in Azure makes no difference.

Very similar issue seems to be reported here

Upvotes: 0

Views: 1915

Answers (2)

Venkat Ayyadevara - MSFT
Venkat Ayyadevara - MSFT

Reputation: 2883

Today, we don't support an authenticated user accessing another user's mail, calendar or contacts using OAuth. That is why your request is failing when you retrieve the conference room's calendar but working for your own calendar. This request works using the browser, because you are using Basic authentication, and we don't recommend this for your app. If you do want to try out requests using OAuth, you can do so using our OAuth sandbox.

The good news is that we are very close to releasing support for OAuth client credential flow that will enable an app, with consent from the tenant admin, to access any mailbox in the tenant. Since you are a tenant admin, as soon as we release this feature, you will be able to authorize the app to access the calendars of your tenant's conference rooms. So, please stay tuned for an announcement in the coming weeks.

[UPDATE]: Support for service accounts is now available. Please see our blog announcement for more details and let us know if you have any questions.

Upvotes: 4

EngineerCoder
EngineerCoder

Reputation: 1455

You have to sent your secret code. And if your program attempt many times may blocked as spammer.

Check it out: http://support2.microsoft.com/kb/2630976

To fix this problem, reset the user's password. To do this, follow these steps: Open a web browser, browse to the Office 365 portal (https://portal.office.com), and then sign in by using the user's expired credentials. When you're prompted, enter a new Office 365 password for the user. Make sure that the password meets the criteria for Office 365.

Upvotes: 0

Related Questions