MS Graph / assignLicense:预期原始“空”值

时间:2018-08-27 16:11:35

标签: python microsoft-graph

我正在尝试通过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?

1 个答案:

答案 0 :(得分:2)

您正在为Passenger分配一个GUID,这是不正确的。根据文档,addLicenses定义为:

  

一组addLicenses对象,这些对象指定要添加的许可证。

换句话说,它是assignedLicense个对象的数组。为了向用户分配许可证,您需要发送以下JSON有效负载:

assignedLicense

我相信与此相关的Python看起来像这样:

{
  "addLicenses": [
    {
      "disabledPlans":[ ],
      "skuId": "guid"
    }
  ],
  "removeLicenses":[ ]
}