Hi All,
It seems over the last couple of weeks changes may have been made that make object classes for standard objects like QUEUE or CAMPAIGN not iterable - so I've had to go through loops (pun intended) to convert the contained information to another format to make it iterable - in order to extract a piece of information>>...
FIrstly - why has this change happened and can it be fixed.
B) Here is my method of doing it --- BUT I'm very open to better ways. (without hacking the SDK package(
Note - This also includes my solution for getting a unique name where the business may have named objects in a similar way (e.g. DefaultOutboundScript, DefaultOutboundScript1)
Here's the bit that gets the data out of the object and turns it into a standard dictionary.
def clean_object(thing):
thing=vars(thing)
keysList= list(thing.keys())
#get the list of keys that start without underscores then remove them
plain_keys = [key for key in keysList if key[0:1] != "_"]
for i in range (0,len(plain_keys)):
del thing[plain_keys[i]]
#get the list of keys that start with underscores
und_keys = [key for key in keysList if key[0:1] == "_"]
#replace entries in dictionary with underscore with entry without underscore and same value
for i in range (0,len(und_keys)):
new_key=und_keys[i][1:]
thing[new_key]=thing.pop(und_keys[i])
#print ("thing= ", thing , "\n thing type = " , type(thing))
return thing
Here is a function that gets the id for a script (and works around that the backend of the API's use a contains clause instead of == ..
def get_unique_script_id(role,name):
api_key = get_token_sdk(role)
api_instance = PureCloudPlatformClientV2.ScriptsApi(api_key)
try:
# Retrieve a list of all divisions defined for the organization
api_response = api_instance.get_scripts(name=name)
script_obj_list=(list(api_response.entities))
script_list=[]
name_list=[]
#this loop iterates through the response and converts the class objects back into dictionaries and produces a list of the names of the scripts that were returned (e.g. ['DefaultOutbound_RED2', 'DefaultOutbound_RED'])
for i in range(0,len(script_obj_list)):
sub_list=clean_object(script_obj_list[i])
script_list.append(sub_list)
#print(type(script_list),script_list)
name_list.append(sub_list.get('name'))
#print (name_list)
#find the index of the exact match and return that id
try:
name_idx=name_list.index(name)
print (name_idx)
script_id=script_list[name_idx]['id']
print (script_id)
#print ("division id = ",script_id)
return script_id
except:
script_id = -1
return script_id
#sys.exit()
except ApiException as e:
print("Exception when calling ScriptsApi->get_scripts %s\n" % e)
sys.exit()