本文介绍了Microsoft Graph Beta - 用户更新 - 目标实体集当前不支持请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I get the following error when Updating a user using Microsoft Graph Beta. Permissions should not be an issue as I'm using the following permissions: user.readwrite.all, directory.readwrite.all. Also, HireDate is of type DateTimeOffSet that I'm getting by converting local DateTime to DateTimeOffSet. So, that should not be an issue either. Question: What could be the cause of the error and how can it be fixed?

Error:

Microsoft.Graph.ServiceException
  HResult=0x80131500
  Message=Code: BadRequest
Message: The request is currently not supported on the targeted entity set

Inner error:
    AdditionalData:
    date: 2020-08-31T13:59:10
    request-id: 4b62576f-6572-414c-b9ef-07ea9a61c101
ClientRequestId: 4b62576f-6572-414c-b9ef-07ea9a61c101

Code:

private async void DataGridUserUpdateButton_Click(object sender, RoutedEventArgs e)
{
  GraphServiceClient graphClient = new GraphServiceClient(authProvider);

  User user = (sender as Button).DataContext as User;

  string id = user.UserPrincipalName;

   var user = new User
   {
     Department = "IT",
     DisplayName = "Bob Doe",
     HireDate = new DateTime(2020, 8, 31, 2, 30, 0),
     JobTitle = "IT Manager"
   };

  await graphClient.Users[sId]
            .Request()
            .UpdateAsync(user);
}
解决方案

According to some test, I met the same issue as yours. I test it in code with both client_credential grant flow and username/password grant flow(and add enough permissions) but none of them succeeded. Then I test it in graph explorer but also failed. It seems the property hireDate can't be updated success.

For a wordaround, I found another property maybe you can use, you can use employeeHireDate. I already test to update this property, it works fine. This property just exists when we use beta graph api and we can't find it neither in v1.0 user properties nor in beta user properties document.

To update employeeHireDate in code, please refer to the code below:

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var user = new User
{
    AdditionalData = new Dictionary<string, object>()
    {
        {"employeeHireDate", "2019-01-01T00:00:00Z"}
    }
};

await graphClient.Users["userId"]
    .Request()
    .UpdateAsync(user);

By the way, you need to pay attention to the properties in beta version because it may be changed in future.

==================================Update==================================

这篇关于Microsoft Graph Beta - 用户更新 - 目标实体集当前不支持请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 01:26