Search code examples
microsoft-graph-api

Can't Update Users with GraphServiceClient


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?


Solution

  • 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);