lola_the_coding_girl lola_the_coding_girl - 5 months ago 51
PHP Question

403 ErrorAccessDenied in Outlook API

Using the Outlook API I am able to pull calendar events. What I'm trying to do next is, if an event has an attendee email, pull the rest of that attendee's contact data from Outlook's contacts REST API. I believe that I have the query right with

?search="foo@bar.com"
in the URL but I'm getting back the following when I do display the response from cURL:

string '{"error":{"code":"ErrorAccessDenied","message":"Access is denied. Check credentials and try again."}}' (length=101)


It seems that my credentials are good enough to get calendar events but are somehow invalid a second later trying to get contacts. What am I missing?

Answer

What permissions does your app request when it authenticates? Assuming you're using the v2 app model to authenticate this is what is passed in the scope parameter in the authorization request URL:

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=<SOME GUID>
&redirect_uri=https%3A%2F%2Fcid.azurewebsites.net&response_type=code
&scope=openid+https%3A%2F%2Foutlook.office.com%2Fmail.read

In order to access contacts you need to have https://outlook.office.com/contacts.read or https://outlook.office.com/contacts.readwrite, depending on if you need write access.