Can't Update Users with GraphServiceClient
Asked Answered
F

2

5

My problem is exactly what it says in the title. If I want to interact with users using MicrosoftGraph, I have a few options:

graphClient.Users.Request.GetAsync()
graphClient.Users.Request.AddAsync()

I would like to see:

graphClient.Users.Request.UpdateAsync()

Unfortunately, my problem is that I don't see it. Where is it? I see UpdateAsync on a few other objects... why is it not on users? Did I miss some crucial piece of documentation?

Farewell answered 2/5, 2017 at 20:54 Comment(0)
D
8

It is on User. You're missing a few things. You haven't identified the user, use the indexer. Also, Request is a method, not a property.

var betterMe = new User()
{
   GivenName = "Super Man"
};

// Update the user to Super Man
await graphClient.Users[myId].Request().UpdateAsync(betterMe);
Dross answered 2/5, 2017 at 21:26 Comment(2)
Thanks, I was typing this from memory, hence the calling Request as a property instead of a method. This appears to be what I was looking for. Thanks!Farewell
Holy Jesus! I could make my code work after getting here and learning from your answer. My SO question here: https://mcmap.net/q/2031542/-resource-39-guid-value-here-39-does-not-exist-or-one-of-its-queried-reference-property-objects-are-not-present/114029Uncle
P
1
var betterMe = new User()
{
   GivenName = "Super Man"
};

await graphClient.Users["{user-id}"].PatchAsync(betterMe);
Petterson answered 24/2 at 0:20 Comment(1)
Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. Would you kindly edit your answer to include additional details for the benefit of the community?Pelvic

© 2022 - 2024 — McMap. All rights reserved.