Removing/clearing custom attribute with Python API for a specific user

I am setting and getting the value of an optional custom attribute via Python API. For example, to set the value:

        r ='',
        headers = {
          'Accept': 'application/json',
          'Content-Type': 'application/json',
          'Authorization' : 'SSWS XXYYZZ' },
        data = '{"profile": {"custom_attr": "attr_value" }}')

And to get the value:

    r = requests.get('',
    headers = {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
      'Authorization' : 'SSWS XXYYZZ' })
  content = json.loads(r.content)
  print content['profile']['custom_attr']

I also have a requirement to remove this optional custom attribute from a specific user profile, but have not found any way to do this and don’t see any reference to this functionality in the API docs.

Any ideas would be greatly appreciated.

I don’t think you can remove the custom attribute from the profile for a user because custom attributes are configured at the profile level, not the user-level.

However, you can “blank” the attribute’s value by simply setting

   payload = {
      "profile": {
         "customAttribute": "",

I did try this before posting my question, but got an error. This custom attribute is defined as an enumerated list of values, and an empty value ("") is invalid value, and I can’t add an “empty” value to the list. I did try this on a different attribute that is not an enumerated list and it works. I guess it’s a limitation with enumerated list attributes.

Thanks for responding.

Create a “blank” value as a potential enumerated list and you should be fine, or edit the profile schema to a generic type (like “string”).

1 Like