0
votes

How do you update the onPremisesExtensionAttributes.extensionAttributes8 on a user using Graph client for example?

Please note that I'm using the beta (Microsoft.Graph.Beta version 0.4.0-preview) for the graph SDK. I don't want to use v1.0 as of now, due to some limitations with v1.0

I've tried this but this does not compile

            var graphServiceClient = CreateGraphServiceClient();
        //graphServiceClient.BaseUrl = "https://graph.microsoft.com/beta";


        var user = graphServiceClient.Users["xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"].Request()
                                                      .Select("id,accountEnabled,mail,OnPremisesExtensionAttributes,userType,displayName,source,externalUserState")
                                                      .GetAsync()
                                                      .Result;            

        User updatedUser = new User()
        {
            OnPremisesExtensionAttributes.ExtensionAttribute8 = "1"
        };

        await graphServiceClient.Users[user.Id].Request().UpdateAsync(updatedUser);
1

1 Answers

1
votes

When setting updatedUser, you initialize a new instance of User, but you forgot to also initialize a new instance of OnPremisesExtensionAttributes before trying to set a value for ExtensionAttribute8.

The following would be a correct way of initializing updatedUser all in one go:

User updatedUser = new User()
{
    OnPremisesExtensionAttributes = new OnPremisesExtensionAttributes()
    {
        ExtensionAttribute8 = "1"
    }
};

Alternatively, you could do the same thing like this:

User updatedUser = new User();
updatedUser.OnPremisesExtensionAttributes = new OnPremisesExtensionAttributes();
updatedUser.OnPremisesExtensionAttributes.ExtensionAttribute8 = "1";