python-3.xmicrosoft-graph-apiflask-oauthlib

A post call to add a new openTypeExtension to user data fails with "Resource not found for the segment 'extensions'"


I've modified sample_flask.py by adding a new action to the graphcall function. The new MSGRAPH.post call should create an openTypeExtension to the user. The code is as follows:

endpoint = 'me/extensions'
data = {
    "@odata.type": "microsoft.graph.openTypeExtension",
    "extensionName": "com.myorgname.appname",
    "permissions": "guest"
}
graphanswer = MSGRAPH.post(endpoint, headers=headers, data=data).data
print(graphanswer)

with the complete endpoint path being https://graph.microsoft.com/v1.0/me/extensions, and I've tried using the absolute uid path as well. Headers are recycled from the get example in the source. Either case results in the following error:

{'error': 
    {'code': 'RequestBroker--ParseUri', 
    'message': "Resource not found for the segment 'extensions'.", 
    'innerError': 
        {'request-id': '<omitted>', 'date': '2019-11-20T23:37:40'}
    }
}

I've checked the token in jwt.ms for the necessary scopes, which I've elevated to User.ReadWrite.All and granted permissions. When I test the post method in Graph Explorer, everything pans out very nicely and the extension is created.

Is there an obvious error here? I've been reading through everything related to "resource not found" errors and openTypeExtension, but haven't found anything pertinent thus far.


Solution

  • Everything looks right (Uri, http method, scenario, token, etc.) but I think the content-type header in your request was application/x-www-form-urlencoded instead of application/json.