Need help updating user - employee ID field using python

Does the "EmployerInfo()" object actually exist? I run the code below, and it completes successfully, but the employee ID field remains unchanged:

api_instance = PureCloudPlatformClientV2.UsersApi(api_client)

print("\n*** Start of User Update ***")
updateuser = PureCloudPlatformClientV2.UpdateUser()
updateuser.version = "22"

newemployeeid = PureCloudPlatformClientV2.EmployerInfo()
newemployeeid.employee_id = "12345"

try:
api_response = api_instance.patch_user("xxxxxxxxxxx",updateuser)
pprint(api_response)
except ApiException as e:
print("*** Exception when calling UsersApi -> patch_user: %s ***\n" % e)

Looks like you're missing a line of code before making the request:

updateuser.employerInfo = newemployeeid

or even easier, don't create a separate object:

updateuser.employerInfo = PureCloudPlatformClientV2.EmployerInfo()
updateuser.employerInfo.employee_id = "12345"

Tim,

Thanks for the prompt reply :slight_smile:

I updated the code with your suggestion, and get identical results - the employee ID is unchanged :frowning:

I can see the employee ID in API Explorer on a GET user only when expanding the employerInfo field - I'm suspecting that I need to also expand the employerInfo field on the PATCH update, and your suggestion seems tio do that, but I'm just guessing at this point:

"version": 22,
"employerInfo": {
"employeeId": "XXXXXXXXXX",
"employeeType": "Full-time"

Does the PATCH request work as expected when you do it it API Explorer? It does for me with this request body:

{
  "employerInfo": {
    "employeeId": "1234"
  },
  "version": 161
}

In your python code, use apiclient.sanitize_for_serialization(...) on the updateuser variable to get a string of the JSON body that's getting sent to the API to verify it's producing the same structure as the working request above.

The PATCH request doesn't support an expand parameter. The object you get back will never have the employerInfo property. You need to do a GET on the user with the expand again to validate the result.

Tim,

Thanks again for the reply :slight_smile:

The PATCH does work as expected in the API explorer. When I ran using the sanitize_for_serialization, I noticed that the JSON body uses "employerInfo" and "employeeId", but python should use "employer_info" and "employee_id". Here's what I finally managed to get working:

updateuser = PureCloudPlatformClientV2.UpdateUser()
updateuser.version = "154"
updateuser.employer_info = PureCloudPlatformClientV2.EmployerInfo()
updateuser.employer_info.employee_id = "12345"

print("*** JSON body ***\n", api_client.sanitize_for_serialization(updateuser))

try:
api_response = api_instance.patch_user("XXXXXXXXXXXXXXX",updateuser)
pprint(api_response)
except ApiException as e:
print("*** Exception when calling UsersApi -> patch_user: %s ***\n" % e)

Thank you so much for your help - couldn't have done it without you. Count me as a feather in your cap for the day :slight_smile:

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