This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Is It Possible to Update a User's Custom Fields Via the API?

Hi All,

I'm trying to automate some user updates via that Solar Winds Service Desk (formerly SAManage) API. We're have a custom field for every user called "empid" - a unique ID per user that's separate from the one the Service Desk generates. Some users are lacking this value and we want to backfill them, so I'm writing code that hits a separate DB, gets their empid, and then updates their Service Desk profile. The problem is, I cannot manage to get the value to show up for users with no existing empid OR change for users with an existing empid that's incorrect. I can change anything else in the user object, but have not been able to get custom fields to change.

I did some research and it appears there's still work being done on the custom fields API but I can't quite tell if that's just for creating NEW custom fields (which we're not trying to do) or for updating them on users, tickets, etc.

I've tried every format I could think of to update the user's custom field, to no avail. Some examples:

updatedUser.custom_fields_values = [
  {
    name: 'Empid',
    value: 12345,
  },
];
and
updatedUser.custom_fields_values = {
  custom_fields_value: [
    {
      name: 'Empid',
      value: 12345,
    },
  ],
};

and
updatedUser.custom_fields_values = {
  custom_fields_value: [
    {
      attachment: null,
      custom_field_id: 4257891,
      entity: null,
      id: 230146872,
      name: 'Empid',
      options: '',
      type: 1,
      type_name: 'Text',
      user: null,
      value: 12345,
    },
  ],
};
With no luck. I'm unsure if it's a formatting issue or if the API's just not set up to do this yet. Any info would be appreciated.
Thanks!
-Chris

Parents
  • We use the API heavily and haven't seen any issues with updating custom fields on user records.  I definitely would recommend submitting a service request if you're still having issues.  I just tested updating my own user through Postman with the following json and it successfully changed.

    {
        "user": {
            "custom_fields_values": {
                "custom_fields_value": [
                    {
                        "name": "EmployeeId",
                        "value": "00"
                    }
                ]
            }
        }
    }

    One thing I noticed is that you seem to have some dangling commas where there shouldn't be if this is being submitted as json.  That often blows up the API request due to an invalid format.  If you removed those extra commas so it looks more like this, does it work?

    updatedUser.custom_fields_values = {
      custom_fields_value: [
        {
          name: 'Empid',
          value: 12345,
        }
      ]
    };
Reply
  • We use the API heavily and haven't seen any issues with updating custom fields on user records.  I definitely would recommend submitting a service request if you're still having issues.  I just tested updating my own user through Postman with the following json and it successfully changed.

    {
        "user": {
            "custom_fields_values": {
                "custom_fields_value": [
                    {
                        "name": "EmployeeId",
                        "value": "00"
                    }
                ]
            }
        }
    }

    One thing I noticed is that you seem to have some dangling commas where there shouldn't be if this is being submitted as json.  That often blows up the API request due to an invalid format.  If you removed those extra commas so it looks more like this, does it work?

    updatedUser.custom_fields_values = {
      custom_fields_value: [
        {
          name: 'Empid',
          value: 12345,
        }
      ]
    };
Children
  • Unfortunately that doesn't change anything - that's just JavaScript code, which has trailing commas. It gets stringified into properly formatted JSON before submitting to SAManage.

    HOWEVER, I did determine the issue!

    I was sending data that looked like this:

    {
      "id": 267194,
      "name": "redacted",
      "email": "redacted@holycross.edu",
      "phone": "redacted",
      "mobile_phone": "redacted",
      "custom_fields_values": {
        "custom_fields_value": [
          {
            "name": "Empid",
            "value": "1234567"
          }
        ]
      }
    }
    When I needed to be sending data that looks like this:
    {
    "user": {
        "id": 267194,
        "name": "redacted",
        "email": "redacted@holycross.edu",
        "phone": "redacted",
        "mobile_phone": "redacted",
        "custom_fields_values": {
          "custom_fields_value": [
            {
              "name": "Empid",
              "value": "1234567"
            }
          ]
        }
      }
    }
    That top-level "user" object is essential.
    What's weird and was confusing me is: I can update fields like name and email WITHOUT the top level user object. So I didn't realize I was missing it in my code, because my updates to everything EXCEPT the custom fields were going through without a problem.
    Anyway, working now!