office-js - Issue with PATCH method of outlook mail REST API returning ErrorAccessDenied
问题描述
We have an outlook add-in for which we need to update the single-value-extended-property of a mail item using it's itemId.
Documentation for updating the extension property: Here
We got the following response for the HTTP call:
Request Url:
PATCH https://outlook.office365.com/api/v2.0/me/messages('{mailItemId}')
Response:
{
"error": {
"code": "ErrorAccessDenied",
"message": "The api you are trying to access does not support item scoped OAuth."
}
}
On tweaking further, we found that there maybe an issue with the auth token that we are using in the request headers. We are using the Outlook's getCallbackTokenAsync
api to fetch the token, with isRest
option set to true for REST token. On searching around in stack-overflow for relevant issues, I found these questions:
These suggest that there maybe a bug in this api, due to which it returns an item scoped token instead of a mailbox scoped one. The payload of an item scoped token contains Exchange.Callback.V1
as the value of the version and Exchange.Callback.V2
for a mailbox scoped one.
We decoded our response token on https://jwt.io/ and found that the token returned was indeed an item scoped one, and hence we are blocked on pushing the updated value of extended-property to the mail item. It was also written that this issue may get resolved in the builds after 16.0.7902.1000. I am trying this on web-browser client for Outlook though, and not sure how the build version is relevant in my case.
Has anyone else faced such behavior recently, or is there any possible work-around for the issue?
************** EDIT ****************
I followed the suggestion in the comment, and am now able to execute the patch request from postman, but not from within the add-in. I get a 400 bad request error in the console. Below is a version of the response with the particular key name and url removed.
{
"_body": {
"error":{
"code":"RequestBodyRead",
"message":"An unexpected instance annotation name '{key name}' was found
when reading from the JSON reader, In OData, Instance
annotation name must start with @."
}
},
"status": 400,
"ok": false,
"statusText": "Bad Request",
"type": 2
}
How can I resolve this ?
解决方案
请查看 getCallbackTokenAsync API 文档:docs.microsoft.com/en-us/office/dev/add-ins/reference/...。您需要在其清单中指定 ReadWriteMailbox 权限。
推荐阅读
- php - 我正在使用 spatie/laravel-sitemap 是否可以为这些 url 设置另一个 APP_URL
- opencv - AttributeError:模块“cv2.cv2”没有属性“MORP_CLOSE”
- reactjs - 从 ant design 测试 onChange 属性的问题
- amazon-web-services - 如何在cdk中运行rds sql种子脚本
- android - onPressed 工作是 Debug/Profile/Release 模式,但不能在 Release apk (Flutter) 中工作
- android - 启动 TWA 时出现白屏
- r - 未调整(?)趋势线,ggplot [R]
- c - 在 free(p) 之前 pthread_mutex_destroy(p) 是强制性的吗?
- javascript - 如何确定一个元素的真实可见性?
- prolog - 断言,如果我们输入 6 作为参数,则生成 A = 6, B = 0... A = 4, B = 2... A = 2, B = 4... A = 0, B = 6 并结束