[英]Microsoft Graph API Nest JSON Request is failed
我正在使用 Python 3.6 开发利用 Microsoft Graph 的应用程序。
在请求使用请求数据作为嵌套 JSON 的 Graph API 时,我得到了非常奇怪的行为。
这是一个成功的请求:
url = f "https://graph.microsoft.com/v1.0/users/{user_id}"
headers = {
'Authorization': f 'Bearer {office365_access_token}',
'Content-Type': 'application/json'
}
data = {
"city": "Tokyo"
}
req = urllib.request.Request(url, json.dumps(data).encode("utf-8"), headers = headers, method = 'PATCH')
urllib.request.urlopen(req)
下一个剪切失败,并显示HTTP Error 400
错误。 文档指出, skills
属性是一个字符串集合,所以我使用了一个字符串值数组:
url = f "https://graph.microsoft.com/v1.0/users/{user_principal_name}"
headers = {
'Authorization': f 'Bearer {office365_access_token}',
'Content-Type': 'application/json'
}
data = {
"skills": ["swift", "python"]
}
req = urllib.request.Request(url, json.dumps(data).encode("utf-8"), headers = headers, method = 'PATCH')
urllib.request.urlopen(req)
唯一的区别是该值是否为字符串。 我可以将数据字典转储为 JSON 字符串,所以我认为代码没有错,但我不知道为什么会出现此错误。
这似乎是一个与 Microsoft Graph 本身相关的错误,特别是与User
更新操作有关。 例如以下查询:
PATCH https://graph.microsoft.com/v1.0/me
Content-type: application/json
{
"skills": [
"Fortran",
"Cobol"
],
"city": "Helsinki"
}
确实失败并返回以下错误:
{
"error": {
"code": "BadRequest",
"message": "The request is currently not supported on the targeted entity set"
}
}
同时更新的另一用户的特性,对于具有同样的例子User.otherMails属性Collection(Edm.String)
类型User.skills
:
PATCH https://graph.microsoft.com/v1.0/me
Content-type: application/json
{
"otherMails": [
"office365admin@gmail.com",
"office365admin@yahoo.com"
],
"city": "Helsinki"
}
成功完成。
解决方法
当User
资源的skills
属性与其他属性一起更新时,它似乎失败了。 但如果只有skills
属性得到更新
PATCH https://graph.microsoft.com/v1.0/me
Content-type: application/json
{
"skills": [
"Fortran",
"Cobol",
"C"
]
}
没有错误发生并且操作成功完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.