有人可以给我一个提示如何使用Microsoft Graph .NET Client Library来设置User.Manager字段吗?我知道how to do this via a direct REST call,但希望尽可能避免这些调用(绕过包装器)。通过下面的代码,我可以清除管理器属性。使用Microsoft Graph .NET客户端库指定管理器
client = new GraphClient(...);
var builder = new DirectoryObjectWithReferenceRequestBuilder(
client.Users["<userid>"].Manager.Request().RequestUrl,client
);
builder.Request().DeleteAsync().Wait()
然而,我仍然无法找出哪些类允许我建立为成员参考(as described here)PUT请求。我尝试了以下代码:
var mgr = new DirectoryObject();
mgr.Id = "<Id of the user that should be set as manager>";
var usrPatch = new User();
usrPatch.Manager = mgr;
client.Users["<Id of the user to be updated>"].Request().UpdateAsync(usrPatch).Wait();
此代码不会引发异常,但它也不会更新管理器。请求是错误的。上面的代码将一个PATCH而不是一个PUT发送到“基本”对象。通过上面的代码生成
请求:
PATCH https://graph.microsoft.com/v1.0/users/[Id of the user to be updated] HTTP/1.1 SdkVersion: graph-dotnet-1.0.1 Content-Type: application/json Host: graph.microsoft.com Content-Length: 45 Expect: 100-continue {"id":"[Id of the user that should be set as manager]"}
响应是一个204
看起来这可能是在图书馆的空白。感谢您指出了这一点。让我检查并回复你。 –