Hello, I'm currently trying to swap 200 + users from the DID being the primary voice to their ext being the primary voice and for some reason the code I have made does not change the primary voice, It should I feel like as it matches exactly what it would be when I manually set the primary voice on my profile to see what it returns but it won't change the primary voice.
def process_user(self,user,group_names):
try:
# derive this user's group names using the cached id->name mapping
user_group_names = {group_names.get(getattr(group, 'id', None)) for group in getattr(user, 'groups', []) or []}
# remove any None values
user_group_names.discard(None)
# exact names to match
target_names = {"GC NSS CL SUPERVISOR", "GC NSS CL USER", "GC NSS PL SUPERVISOR", "GC NSS PL USER"}
matched = user_group_names.intersection(target_names)
if matched:
body = PureCloudPlatformClientV2.UpdateUser()
body.version = user.version
updated_primary_contact_info = []
#print(f"User {user.id}, name: {user.name}, matched groups: {matched}")
for address in user.addresses:
print(f"Address: {address}")
ext = getattr(address, 'extension', None)
if ext == None or ext == "":
# if "primary" in address and address.primary == True:
# address.primary = False
continue
else:
users_ext = ext
#print(f"Extension: {users_ext}")
#address.primary = True
for address in user.primary_contact_info:
if address.media_type == "PHONE" and address.type == "PRIMARY":
print (f"Before Update - {address}")
address.address = None
address.display = users_ext
address.extension = users_ext
#print(f"After Update - {address}")
updated_primary_contact_info.append(address)
else:
updated_primary_contact_info.append(address)
body.primary_contact_info = updated_primary_contact_info
body.addresses = user.addresses
#print(f"body:\n {body}")
try:
resp = self.users_api.patch_user(user.id, body)
print("patched: \n", resp)
except Exception as e: print("API error:", e)
# return {
# 'id': getattr(user, 'id', None),
# 'name': getattr(user, 'name', None),
# 'matched_groups': list(matched),
# 'primary_contact_info': getattr(user, 'primary_contact_info', None)
# }
return None