Hello I am trying to add multiple wrapup codes to a Queue using below code,:-
wrapup_code_id= ["123-abcd",
"5468-abcde"
]
queueid='e03cf2a0-b982'
create an instance of the API class
routingapi = routing_api.RoutingApi(apiclient)
for name in wrapup_code_name:
try:
# Update wrap-up code to Queue
body = PureCloudPlatformClientV2.WrapUpCodeReference()
body.name = name
api_response = routingapi.post_routing_queue_wrapupcodes(queueid,body)
pprint(api_response)
except ApiException as e:
print("Exception when calling RoutingApi->post_routing_wrapupcodes: %s\n" % e)
getting below error:-
Exception when calling RoutingApi->post_routing_wrapupcodes: (400)
Reason: Bad Request
HTTP response body: {"message":"The request could not be understood by the server due to malformed syntax.","code":"bad.request","status":400,"contextId":"229d0a23-ff04-45e6-a9cc-441b3b5c253d","details":[],"errors":[]}
Could you help me understanding what exactly am I doing wrong and how to fix it?
post_routing_queue_wrapupcodes takes a list of WrapUpCodeReference objects whereas you are sending in a single object. Instead you'll need to create the WrapUpCodeReference inside the loop and add it to a list and then after the loop has finished, call the api with the list of WrapUpCodeReferences like so:
wrap_up_codes = []
for name in wrapup_code_name:
wrap_up_code = PureCloudPlatformClientV2.WrapUpCodeReference()
# Add properties
wrap_up_codes.append(wrap_up_code)
try:
api_response = routingApi.post_routing_queue_wrapupcodes(queueId,wrap_up_codes)
print(api_response)
except ApiException as e:
print("Exception when calling RoutingApi->post_routing_wrapupcodes: %s\n" % e)
#queue ID where you want to add Wraup Codes
queueid='e03cf2a0'
Placeholder to hold WrapupCodeReference Objects
wrap_up_codes = []
for code_id in wrapup_code_ids :
wrap_up_code=PureCloudPlatformClientV2.WrapUpCodeReference()
wrap_up_codes.append(wrap_up_code) #wrap_up_codes.append(wrap_up_code)
try:
api_response = api_instance.post_routing_queue_wrapupcodes(queueid,wrap_up_codes)
pprint(api_response)
except ApiException as e:
print("Exception when calling RoutingApi->post_routing_wrapupcodes: %s\n" % e)
Error:-
Exception when calling RoutingApi->post_routing_wrapupcodes: (400)
Reason: Bad Request
HTTP response body: {"message":"No valid wrap-up codes were provided in the request.","code":"bad.request","status":400,"messageWithParams":"No valid wrap-up codes were provided in the request.","messageParams":{},"contextId":"5ecd4436-6e46-4449-897f-0f79e9561535","details":[],"errors":[]}
Process finished with exit code 0
I have also tried with wrap_up_code name, but I don't think that's the issue, as the function is expecting a wrapup Code ID.
Inside your loop you will need to set the id of WrapUpCodeReference to be the id of the wrapup code you wish to add to the routing queue. If you already have a list of the ids you can simply modify your code like so:
for code_id in wrapup_code_ids:
wrap_up_code = PureCloudPlatformClientV2.WrapUpCodeReference()
wrap_up_code.id = code_id
wrap_up_codes.append(wrap_up_code)