在 python 中,我尝试使用 MS Graph API 将许可证分配给 Office365 中的用户。
request_url = "https://graph.microsoft.com/v1.0/users/myuser@mydomain.ca/assignLicense"
headers = {
'Authorization' : 'Bearer ' + token,
'Content-Type' : 'application/json',
}
response = requests.post(url = request_url, headers = headers, json={'addLicenses': 'testGUID'})
但是,我收到以下错误消息:
{
"error": {
"code": "Request_BadRequest",
"innerError": {
"date": "2018-08-27T15:56:45",
"request-id": "9ddde6c8-5fe1-4425-ba84-bc49fa35e2b8"
},
"message": "When trying to read a null collection parameter value in JSON Light, a node of type 'PrimitiveValue' with the value 'test' was read from the JSON reader; however, a primitive 'null' value was expected."
}
}
如何从 python 调用 allocateLicense?
最佳答案
您将 GUID 分配给 addLicenses
,这是不正确的。从文档中,addLicenses
定义为:
A collection of
assignedLicense
objects that specify the licenses to add.
换句话说,它是一个 assignedLicense
的数组对象。为了向用户分配许可证,您需要发送以下 JSON 负载:
{
"addLicenses": [
{
"disabledPlans":[ ],
"skuId": "guid"
}
],
"removeLicenses":[ ]
}
我相信 Python 看起来像这样:
request_url = "https://graph.microsoft.com/v1.0/users/myuser@mydomain.ca/assignLicense"
headers = {
'Authorization' : 'Bearer ' + token,
'Content-Type' : 'application/json',
}
data = [
"addLicenses": [
{
"disabledPlans":[ ],
"skuId": "GUID"
}
],
"removeLicenses":[ ]
]
requests.post(url, json=data, headers=headers)
关于python - MS Graph/分配许可证 : primitive 'null' value was expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52043224/