Update User contact info - Want to remove MOBILE field only

All of the user's contact info gets overwritten when trying to remove only their MOBILE number. Is there a way to leave the other contact fields untouched? Here is the contact info before, the code that was run, and the contact info fields after:

Before

"primaryContactInfo": [
{
"address": "Joe.Smith@acme.com",
"mediaType": "EMAIL",
"type": "PRIMARY"
},
{
"address": "+18005551212",
"mediaType": "SMS",
"type": "PRIMARY"
},
{
"address": "+18885551212",
"display": "+1 888-555-1212",
"mediaType": "PHONE",
"type": "PRIMARY"
}
],
"addresses": [
{
"address": "+18775551212",
"display": "+1 877-555-1212",
"mediaType": "SMS",
"type": "MOBILE",
"countryCode": "US"
},
{
"address": "+18665551212",
"display": "+1 866-555-1212",
"mediaType": "PHONE",
"type": "WORK",
"countryCode": "US"
}
]

After

"primaryContactInfo": [
{
"address": "Joe.Smith@acme.com",
"mediaType": "EMAIL",
"type": "PRIMARY"
}
],
"addresses": []

Code

api_instance = PureCloudPlatformClientV2.UsersApi(api_client)

print("\n*** Start of User Update ***")
updateuser = PureCloudPlatformClientV2.UpdateUser()
updateuser.version = "8"
contact = PureCloudPlatformClientV2.Contact()
contact.address = None
contact.display = ""
contact.media_type = "SMS"
contact.type = "MOBILE"
contact.country_code = ""
updateuser.addresses = [contact]

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

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

Hello,

If you are trying to remove the SMS/MOBILE entry and to keep the PHONE/WORK one, then you need to send the PHONE/WORK address in your PATCH request.
I mean that the addresses attribute works as a "replace" (even if the method is a PATCH).
The array of addresses you send in your PATCH request will replace the existing one.

So you would need to get the user information first, extract the addresses from the response (and version), remove your SMS/MOBILE entry from this array, and use this modified array in your PATCH request.

Sending:
"addresses": [
{
"address": "+18665551212",
"display": "+1 866-555-1212",
"mediaType": "PHONE",
"type": "WORK",
"countryCode": "US"
}
]

Regards,

Thank you Jerome for the reply :slight_smile:
I was hoping it wouldn't be that difficult, but your reply confirms my fear. Wish it was better news, but it at least gives me a direction to go in ... Thanks again.

Robert Voor

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