【问题标题】:How to update existing user in Azure AD using Microsoft Graph API如何使用 Microsoft Graph API 更新 Azure AD 中的现有用户
【发布时间】:2019-06-06 13:29:07
【问题描述】:

我在 azure 广告中添加了一个用户。现在使用graph api 我想更新它的显示名称或者说密码。我指的是这个指南https://docs.microsoft.com/en-us/graph/api/user-update?view=graph-rest-1.0&tabs=cs

首先,我不确定我是否使用正确的 URL 来更新用户,但以下是我正在使用的:

 https://graph.microsoft.com/v1.0/users/john@<myorg>.onmicrosoft.com

我正在传递我想在 url 中更新的用户的 userName。如果这不正确,请告诉我。

我在我的请求中包含OAuth token 作为不记名令牌并发布以下 json:

{
  "accountEnabled": true,

  "displayName": "john12"

}

从上面的 json 中,我想将显示名称从 john 更改为 john12。但我得到以下错误:

{
    "error": {
        "code": "Request_BadRequest",
        "message": "Specified HTTP method is not allowed for the request target.",
        "innerError": {
            "request-id": "536fd7c1-db46-4927-9732-169da778811c",
            "date": "2019-06-06T04:58:26"
        }
    }
}

请任何人告诉我如何更新现有的用户属性。谢谢

【问题讨论】:

    标签: azure azure-active-directory microsoft-graph-api


    【解决方案1】:

    很可能您没有使用 HTTP 方法 PATCH。我这样说是看着错误信息Specified HTTP method is not allowed for the request target.

    如果您使用 PATCH 以外的任何内容,例如 POST,您最终会收到此错误消息。

    您的请求的 JSON 正文看起来不错。我尝试使用类似的 JSON 更新现有用户并从 Microsoft Graph Explorer 发送 PATCH 请求,它工作正常。

    当我从 Microsoft Graph Explorer 使用 POST 或 PUT 调用时,我可以重现您看到的相同错误消息。

    虽然将 POST 更改为 PATCH 后,具有相同 JSON 正文的相同请求 URL 工作正常。稍后再次查询用户(GET),我可以看到 displayName 已正确更新

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多