1

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.

1 Answer 1

1

It appears to be a bug related with Microsoft Graph itself, specifically with User update operation. For example the following query:

PATCH https://graph.microsoft.com/v1.0/me
Content-type: application/json
{
  "skills": [
    "Fortran",
    "Cobol"
  ],
  "city": "Helsinki"
}

indeed fails and returns the following error:

{
    "error": {
        "code": "BadRequest",
        "message": "The request is currently not supported on the targeted entity set"
    }
}

At the same time updating another User properties, for example User.otherMails property which has the same Collection(Edm.String) type as User.skills:

PATCH https://graph.microsoft.com/v1.0/me
Content-type: application/json


{
  "otherMails": [
    "[email protected]",
    "[email protected]"
  ],
  "city": "Helsinki"
}

completes successfully.

Workaround

It appears it fails when skills property of User resource is getting updated along with another properties. But if only a skills property is getting updated

PATCH https://graph.microsoft.com/v1.0/me
Content-type: application/json

{
  "skills": [
    "Fortran",
    "Cobol",
    "C"
  ]
}

no error occurs and the operation successfully completes.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your comment. But my request is only updating skills property and the request fails.
@penlight, surprisingly, your example for updating skills property only works on my side

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.