如何通过Office365 API向用户添加多个角色?

时间:2019-06-27 10:42:14

标签: office365 azure-ad-graph-api

我想一次通过office365 api向用户添加多个角色。

但是通过api,哪个链接是 https://docs.microsoft.com/en-us/graph/api/directoryrole-post-members?view=graph-rest-1.0&tabs=javascript

我使用如下所示的api

POST https://graph.microsoft.com/beta/directoryRoles/{roleId}/members/$ref

Request Body(which type is [directoryObject][https://docs.microsoft.com/en-us/graph/api/resources/directoryobject?view=graph-rest-1.0]):
{
  "id": "697c1e95-7184-45bc-a24b-2262b1b00bc7"
}

但是api返回

{
    "error": {
        "code": "Request_BadRequest",
        "message": "An unexpected 'EndOfInput' node was found when reading from the JSON reader. A 'StartObject' node was expected.",
        "innerError": {
            "request-id": "af3f38c5-bc87-4136-bae2-643c84a23281",
            "date": "2019-06-27T09:33:10"
        }
    }
}

我认为应该有问题,但是我找不到问题。

有人可以帮忙吗?可能是我使用了错误的api吗?

1 个答案:

答案 0 :(得分:1)

基于Graph API文档(Add directory role member),POST正文应该是指向用户的odata链接。

enter image description here

我获得了如下成功: enter image description here