I try to subscribe to Office 365 Management API and fail.
posting to https://manage.office.com/api/v1.0/{tennant-id}/activity/feed/sub scriptions/start?contentType=Audit.SharePoint Returns with the following error:
<Response [401]> {"Message":"Authorization has been denied for this request."}
When using local python environment. I already have access Token, which I use it to print the office 365 root website and connect to Azure Active Directory. I suspected the error was in the way I created the Microsoft azure web app, therefore I created a new azure web-app which ended with the same result, also when I creating “Native Client app” ended with the same result. When I use an 'web app python console', for exampl 'pythonanywhere', an exception is being thron, with the following error: “Cannot connect to proxy. Socket error: Tunnel connection failed: 403 Forbidden.”
I followed Microsoft Manual: https://msdn.microsoft.com/en-us/library/office/mt227394.aspx#StartSubscription
Sample of my code:
tid = {my tenant ID}
subscriptionHeader = { 'Content-Type': 'application/json; utf-8' , 'Authorization': 'Bearer %s' % (access_token)}
subscriptionBody = {"webhook" : {
"address": {my site} } }
subscribtionPostUrl = "https*://manage.office.com/api/v1.0/%s/activity/feed/subscriptions/start?contentType=Audit.SharePoint" %(tid)
print ("posting to %s\n" % (subscribtionPostUrl) )
subscribtionPost = requests.post(subscribtionPostUrl, data=subscriptionBody, headers=subscriptionHeader)
print ("subscribtionPost %s\n" % (subscribtionPost ) )
print ("subscribtionPost %s\n" % (subscribtionPost.text ) )