python - MS Graph/分配许可证 : primitive 'null' value was expected

标签 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(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/

相关文章:

python - 性能:扩大二值图像(形态膨胀)

azure - AccessDenied,scp 或角色声明需要出现在 token 中

javascript - 在 O365 中创建群组

azure - 添加 OAuth 客户端 key 的 MS Graph 权限过于广泛

azure - 使用 graph api createEvent 创建事件的发布请求抛出 "OrganizationFromTenantGuidNotFound"错误

python - 在 AWS Lambda 上迁移到 arm64 显示错误 : Unable to import module 'encryptor-lambda'

python - 如何检查 Django 模型的两个实例在一组属性中是否相同并相应地注释查询集?

python - 快速取 .numpy 数组中每 N 行平均值的方法

Python-pandas 将 NA 替换为数据框中一组的中位数或均值

outlook - 使用 Microsoft Graph API 获取过去 24 小时内的电子邮件