Update user metadata with ManagementApi Client

I’m trying to update the user_metadata using the .NET ManagementApi client. I see the UserMetadata property, and can get the values. However, I’m not seeing how to set the values. When I try to update it directly, like below, I get the following error: RuntimeBinderException: Cannot perform runtime binding on a null reference

Anyone have any examples of how they do this?

  • Which SDK this is regarding: e.g. auth0-node
    .NET Package, Auth0.ManagementApi
  • SDK Version: e.g. 2.29.0
    7.12.0
  • Platform Version: e.g. Node 12.19.0
    .NET 6
  • Code Snippets/Error Messages/Supporting Details/Screenshots:
    var userUpdateRequest = new UserUpdateRequest()
    {
    FirstName = firstName,
    LastName = lastName
    };
    userUpdateRequest.UserMetadata.PhoneNumber = phoneNumber;
    return await _auth0ManagementClient.Users.UpdateAsync(userId, userUpdateRequest);

Is this a feature request or bug report? If so, please create an issue directly in the corresponding GitHub repo. The Community SDK category is for general discussion and support.
Nope

Hi @RunLong,

Welcome to the Auth0 Community!

To update the user’s user_metadata with the ManagementClient, you need to call the updateUserMetadata method. See below for an example.

var params = { id: USER_ID };
var metadata = {
  address: '123th Node.js Street'
};

management.updateUserMetadata(params, metadata, function (err, user) {
  if (err) {
    // Handle error.
  }

  // Updated user.
  console.log(user);
});

You may find the updateUserMetadata reference useful.

Please let me know if there’s anything else I can do to help.

Thanks.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.