[英]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.