Office 365 REST API(Python)将电子邮件标记为已读

我确定我做了一些简单的错误,但我不能为我的生活弄清楚如何将“IsRead”属性设置为true.这是我的流程的最后一步,它获取了一个过滤的消息列表,并存储和处理任何附件.

根据文档“IsRead”是可写的:http://msdn.microsoft.com/office%5Coffice365%5CAPi/complex-types-for-mail-contacts-calendar#ResourcesMessage

http://msdn.microsoft.com/office%5Coffice365%5CAPi/mail-rest-operations#MessageoperationsUpdatemessages

我正在使用python 2.7和请求模块:

# once file acquired mark the email as read
params = {'IsRead':'True'}
base_email_url = u'https://outlook.office365.com/api/v1.0/me/messages/{0}'.format( msgId )
response = requests.patch(base_email_url, params, auth=(email,pwd))
log.debug( response )

回复的反应如下:

{"error":{"code":"ErrorInvalidRequest","message":"Cannot read the request body."}}

我的要求有什么问题?

最佳答案
乍一看它看起来还不错.我想知道Content-Type标头是不是被设置为“application / json”或者是那些行.尝试获取网络跟踪并验证请求是否类似于:

PATCH https://outlook.office365.com/api/v1.0/Me/Messages('msgid') HTTP/1.1
Accept: application/json;odata.metadata=full
Authorization: Bearer <token>
Content-Type: application/json;odata.metadata=full
Host: outlook.office365.com
Content-Length: 24
Expect: 100-continue
Connection: Keep-Alive

{
  "IsRead": "true"
}

转载注明原文:Office 365 REST API(Python)将电子邮件标记为已读 - 代码日志