OKTA User Update

I am using Okta C# sdk for development. I have created some custom user profile attributes in the Okta. I am able to create user and save values in custom attributes. But as I saw that when you update profile data you have to provide all the details again. If you provide specific attributes value then sets null for other attributes. So how can I update only one or two attributes so that other should not change.

My code:
var oktaClient = new OktaClient(Apikey, new Uri(ApiUrl));

            var usersClient = oktaClient.GetUsersClient();
            //var CurrentUser = usersClient.Get("emailid");
       

            foreach (string key in Attributes.Keys)
            {
                if (CurrentUser.Profile.ContainsProperty(key))
                {
                    //user.Profile.SetProperty(key, Attributes[key]);
                    CurrentUser.Profile.GetProperty(key);
                }
                else
                {
                    if (Attributes[key] != null)
                        CurrentUser.Profile.SetProperty(key, Attributes[key]);
                }
            }

          
            CurrentUser = usersClient.Update(CurrentUser);

*ERROR:Unable to serialize the object properly

Hey @Praveenvid, I wasn’t able to reproduce this issue. Here’s what I tried:

var oktaClient = new OktaClient("api-key", new Uri("org-url"));
var usersClient = oktaClient.GetUsersClient();

// Get a user and update a custom profile property
var user = usersClient.Get("user-id");
user.Profile.SetProperty("customProperty1", "testing");
usersClient.Update(user);

// Get the same user and update a different property
var user2 = usersClient.Get("user-id");
user2.Profile.SetProperty("customProperty2", "foobar");
usersClient.Update(user2);

After running this code, the user has both properties set. Setting customProperty2 didn’t null out the first property.

I may have misunderstood your issue. Let me know if this doesn’t match what you are trying to do.

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