如何使用Azure图形API创建用户

时间:2019-06-03 11:28:42

标签: azure azure-ad-graph-api

我正在尝试使用azure graph API创建用户。为此,我得到了令牌响应,如下所示:

enter image description here

获得令牌后,我将其添加为以下URL中的授权令牌:

https://graph.microsoft.com/v1.0/users

并发布以下json数据:

{
  "accountEnabled": true,
  "displayName": "Andrew",
  "mailNickname": "SanAndrew",
  "userPrincipalName": "andrew.san204@gmail.com",
  "passwordProfile" : {
    "forceChangePasswordNextSignIn": true,
    "password": "password"
  }
}

但是出现以下错误:

{
    " error": {
        "code": "Authorization_RequestDenied",
        "message": "Insufficient privileges to complete the operation.",
        "innerError": {
            "request-id": "c06079d2-ff6b-4e5b-b34d-704f16bc312f",
            "date": "2019-06-03T11:20:20"
        }
    }
}

尽管我拥有所有权限,如下所示:

enter image description here

有人可以在这里建议我做错了吗。

1 个答案:

答案 0 :(得分:1)

该错误的一种可能是您正在尝试使用gmail.com域创建用户。该域必须是您AAD租户中已验证的域之一。

如果仍然要添加gmail.com用户,则需要通过邀请端点发送邀请:https://docs.microsoft.com/en-us/graph/api/invitation-post?view=graph-rest-1.0&tabs=cs