update a users profile field

update a users profile field

This question is answered

in Community 6.0 how can up update a users' profile field either using velocity or the REST api?  Anyone have an example?

Verified Answer
  • Ok, so here is an example using the REST API

               string apiEndPoint = ConfigurationManager.ConnectionStrings["REST"] + "/v2/users/sthomas.xml";

               var WebClient = new WebClient();

               var key = String.Format("{0}:{1}", "xxx", "xxx");

               var key64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(key));

               WebClient.Headers.Add("Rest-User-Token", key64);

               WebClient.Headers.Add("Rest-Method", "PUT");

               var values = new NameValueCollection();

               values.Add("_ProfileFields_Skills", "Walking");

               WebClient.UseDefaultCredentials = true;

               var xml = WebClient.UploadValues(apiEndPoint, values);

All Replies
  • You can update a user's profile fields through the REST API the same way you update a user.

    Documentation on the Update User endpoint is here:

    http://telligent.com/community/developers/w/developer6/update-a-user.aspx

    The Rest Request would look like the following if you wanted to set the Location Profile field to Dallas, TX.

    <Request>
       <Id>2104</Id>
       <ProfileFields>
         <Location>Dallas, TX</Location>
       </ProfileFields>
    </Request>

    There is an example of the use of this REST endpoint to update profile fields in the User Profile Fields widget.

  • Steven,

    Please let us if your issue has been resolved.

    Regards,

  • To add to this, in 6.0, profile fields can be updated alongside other non-profile field properties of a user when performing updates against REST or the Widget (Velocity) API with the format _ProfileFields_FIELDNAME = 'FIELDVALUE'

    For example, from the Widget API:

    $core_v2_user.Update("%{ Id = 1234, Bio = 'new value for this non-profile field', _ProfileFields_Twitter = 'New Value for Twitter profile field' })

    Additionally, in 6.1, the same pattern is supported for Extended Attributes on all entity types.

    _ExtendedAttributes_NAME = 'VALUE'

    Hope this helps!

  • Hi Michael,

    I assume this is then also possible using the PublicAPI? I can't quite work out how to update a profile field though. This is my attempt so far:

              Telligent.Evolution.Extensibility.Api.Version1.UsersUpdateOptions userUpdateOptions = new Telligent.Evolution.Extensibility.Api.Version1.UsersUpdateOptions();

              IList<Telligent.Evolution.Extensibility.Api.Entities.Version1.ProfileField> profileFieldList;

              profileFieldList.Add(new Telligent.Evolution.Extensibility.Api.Entities.Version1.ProfileField { Label = "myProfileField", Value = "new value" });

              userUpdateOptions.ProfileFields = profileFieldList;

              Telligent.Evolution.Extensibility.Api.Version1.PublicApi.Users.Update(userUpdateOptions);

    Thanks

    Adam

  • Actually, that approach for the Public API should work (assuming the UserUpdateOptions also contains a UserName or Id, and the ProfileFields are initialized to some list instance)...   It's what's called by the Widget and REST APIs.

    Are you receiving an error?  If you pass other fields with that same call to Update(), do they update?

  • Ok, so here is an example using the REST API

               string apiEndPoint = ConfigurationManager.ConnectionStrings["REST"] + "/v2/users/sthomas.xml";

               var WebClient = new WebClient();

               var key = String.Format("{0}:{1}", "xxx", "xxx");

               var key64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(key));

               WebClient.Headers.Add("Rest-User-Token", key64);

               WebClient.Headers.Add("Rest-Method", "PUT");

               var values = new NameValueCollection();

               values.Add("_ProfileFields_Skills", "Walking");

               WebClient.UseDefaultCredentials = true;

               var xml = WebClient.UploadValues(apiEndPoint, values);