Python MS Graph/assignLicense:primitive';空';价值是预期的

Python MS Graph/assignLicense:primitive';空';价值是预期的,python,microsoft-graph-api,Python,Microsoft Graph Api,在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

在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调用assignLicense?

您将GUID分配给
addLicenses
,这是不正确的。从文档中,
addLicenses
定义为:

指定要添加的许可证的
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)

没错,看起来
removeLicenses
是必需的属性。我相信您得到的错误来自空字符串(
['']
)。我已经更新了上面的示例,以反映额外的道具。我收到了相同的错误,无法从该消息中找出任何东西!希望错误消息更有意义。