gpt4 book ai didi

azure - 如何使用 Microsoft Graph API 更新 Azure AD 中的现有用户

转载 作者:行者123 更新时间:2023-12-03 02:50:15 24 4
gpt4 key购买 nike

我已在 azure 广告中添加了用户。现在使用 graph api 我想更新其显示名称或密码。我指的是本指南https://learn.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

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

我将 OAuth token 作为不记名 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"
}
}
}

请问谁可以告诉我如何更新现有的用户属性。谢谢

最佳答案

很可能您没有使用 HTTP 方法 PATCH。我说这个是看错误消息请求目标不允许指定的HTTP方法。

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

您的请求的 JSON 正文看起来不错。我尝试使用类似的 JSON 更新现有用户,并从 Microsoft Graph Explorer 发送 PATCH 请求。并且效果很好。

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

enter image description here

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

enter image description here

关于azure - 如何使用 Microsoft Graph API 更新 Azure AD 中的现有用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56471145/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com