I am developing App leveraging Microsoft Graph using Python 3.6.
I am getting very strange behavior when requesting Graph API which uses request data as nested JSON.
This is a successful request:
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)
The next snipped fails with an HTTP Error 400 error. The documentation states that the skills property is a String Collection, so I used an Array of String values:
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)
The only difference is whether the value is a string or not. I can dump the data dictionary to a JSON string, so I don't think the code is wrong but I do not know why this error occurres.