Update Canned response for a queue

Hello Team - We have large number of queues where we want to update :-

  1. For some queues to a specific canned response
  2. and for some queue to "None".

Below is a python code attempting to set the canned response to "Null", It's not throwing any exception, What I am doing wrong that it's not updating the canned response to "Null" .

def update_queue_canned_response(queue_id):
"""
Retrieves a queue,

Args:
    queue_id (str): The ID of the queue to update.
"""

try:
    # Create API clients
    routing_api_client = routing_api.RoutingApi(apiclient)
    conversations_api_client = conversations_api.ConversationsApi(apiclient)

    # Get the queue details
    queue = routing_api_client.get_routing_queue(queue_id)
    queue.cannedResponseLibraries = []

    print(f"Queue '{queue.name}' canned response updated")


except ApiException as e:
    print(f"Exception when updating queue: {e}")

Example usage (replace with the actual queue ID)

queue_id_to_update = "74e05603-6b92-435a-be4a-075a131ea824"
update_queue_canned_response(queue_id_to_update)

Hi,

Some things that would be stopping the queue form being updated:

  • In python, properties are named using snake_case so you will need to use queue.canned_response_libraries to access the cannedResponseLibraries property on the queue

  • queue.canned_response_libraries is an object so you can't set it to an empty array, you will need to set it to null like so,

queue.canned_response_libraries = None

Also, GET /api/v2/routing/queues/{queueId} returns a Queue object while PUT /api/v2/routing/queues/{queueId} takes a QueueRequest object so make sure to create a QueueRequest object before calling the update API.

Regards,
Declan

Thanks Declan, I will make suggested changes and try again.

I have updated the request as below:-

import PureCloudPlatformClientV2
from PureCloudPlatformClientV2.rest import ApiException
from PureCloudPlatformClientV2.apis import routing_api, conversations_api
from PureCloudPlatformClientV2.models import Queue, MediaTranscription
from PureCloudPlatformClientV2.configuration import Configuration
from pprint import pprint

region = PureCloudPlatformClientV2.PureCloudRegionHosts.us_east_2
PureCloudPlatformClientV2.configuration.host = region.get_api_host()
apiclient = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token("80bc5d03","T8C_")
authApi = PureCloudPlatformClientV2.AuthorizationApi(apiclient)

"""Create an instance of the API class"""
api_instance = PureCloudPlatformClientV2.RoutingApi(apiclient)

"""Define the queue ID"""
queue_id = '74e05603'

body = PureCloudPlatformClientV2.QueueRequest()

body.name = "TestQueue"
body.canned_response_libraries = None
body.mode= None

try:

Update the queue

api_response = api_instance.put_routing_queue(queue_id, body)
print("Queue updated successfully!")
print(api_response)

except ApiException as e:
print("Exception when calling RoutingApi->put_routing_queue: %s\n" % e)

But its still not updating the queue, when I type the word body and start typing canned, it's not showing any suggestion for canned or for library_ids, is there a fuction available for updating the canned response or not, Is the above code correct or would need further modification.

Kindly help.

Thanks!!

Hi @Shakti_Joshi,

It sounds like your version of our SDK might be out of date, try updating to the latest version and trying again.

Regards,
Declan

Hello @Declan_ginty .. It seems I am already on the updated version

PS C:\Users\sjoshi\Desktop\python_projects> pip install PureCloudPlatformClientV2
Requirement already satisfied: PureCloudPlatformClientV2 in c:\users\sjoshi\appdata\local\programs\python\python312\lib\site-packages (196.0.0)
Requirement already satisfied: urllib3>=1.15 in c:\users\sjoshi\appdata\local\programs\python\python312\lib\site-packages (from PureCloudPlatformClientV2) (2.2.1)
Requirement already satisfied: six>=1.10 in c:\users\sjoshi\appdata\local\programs\python\python312\lib\site-packages (from PureCloudPlatformClientV2) (1.16.0)
Requirement already satisfied: certifi in c:\users\sjoshi\appdata\local\programs\python\python312\lib\site-packages (from PureCloudPlatformClientV2) (2024.2.2)
Requirement already satisfied: python-dateutil in c:\users\sjoshi\appdata\local\programs\python\python312\lib\site-packages (from PureCloudPlatformClientV2) (2.9.0.post0)
Requirement already satisfied: watchdog>=2.1.2 in c:\users\sjoshi\appdata\local\programs\python\python312\lib\site-packages (from PureCloudPlatformClientV2) (4.0.0)

Hello @Declan_ginty ... Can you please help here?

Hi @Shakti_Joshi

I made this script to create a queue and then update the canned response, hope it helps.

import os
import sys
import uuid

import PureCloudPlatformClientV2
from PureCloudPlatformClientV2.rest import ApiException

CLIENT_ID = os.environ['GENESYSCLOUD_OAUTHCLIENT_ID']
CLIENT_SECRET = os.environ['GENESYSCLOUD_OAUTHCLIENT_SECRET']

apiclient = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token(CLIENT_ID, CLIENT_SECRET)

api_instance = PureCloudPlatformClientV2.RoutingApi(apiclient)

# Create Queue with no canned response
queueCreate = PureCloudPlatformClientV2.CreateQueueRequest()
queueCreate.name = "Test queue " + str(uuid.uuid4())
cannedResponse = canned_response_libraries = PureCloudPlatformClientV2.CannedResponseLibraries()
cannedResponse.library_ids = ["id1", "id2"]
cannedResponse.mode = "SelectedOnly"
queueCreate.canned_response_libraries = cannedResponse

global queue
try:
    queue = api_instance.post_routing_queues(queueCreate)
    print(queue)
except ApiException as e:
    print("Exception when calling RoutingApi->post_routing_queue: %s\n" % e)
    sys.exit()

# Update Queue with no canned response
queueUpdate = PureCloudPlatformClientV2.QueueRequest()
queueUpdate.name = "New queue name"
queueUpdate.canned_response_libraries = None

try:
    queue = api_instance.put_routing_queue(queue.id, queueUpdate)
    print(queue)
except ApiException as e:
    print("Exception when calling RoutingApi->post_routing_queue: %s\n" % e)
    sys.exit()

# Delete queue
try:
    print("Deleting queue ", queue.id)
    api_instance.delete_routing_queue(queue.id)
    print("Deleted queue ", queue.id)
except ApiException as e:
    print("Exception when calling RoutingApi->delete_routing_queue: %s\n" % e)

I will need more context and the error messages you are getting to be able to assist further.

Regards,
Declan

Hello @Declan_ginty --- I appreciate your response, and here is the Python code, I have added output for raw body and request body and I don't see canned Response to be part of it, for that matter, I don't see "CannedResponse" to be part of either "Raw Body", "Request Body" or finally in the Successful message. So the question would be is this API, even doing what its suppose to do, as the Request body doesn't have canned_response reference, However if you would closely see, it does have Queue Name reference:-

queueUpdate.name = "TACS_Email" ---- You see this in the request
queueUpdate.canned_response_libraries = None ---- But you don't see this going in the request.

apiclient = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token("HANDLE CLIENT CREDENTIALS AS SECRETS","HANDLE CLIENT CREDENTIALS AS SECRETS")
"""Create an instance of the API class"""
api_instance = PureCloudPlatformClientV2.RoutingApi(apiclient)
canned_response_libraries = PureCloudPlatformClientV2.CannedResponseLibraries

"""Define the queue ID"""
queue_id = 'bd77dcbc-01b5-4e0e-80c1-515a820ba4d1'

queueUpdate = PureCloudPlatformClientV2.QueueRequest()
print("Raw Body",queueUpdate)
queueUpdate.name = "TACS_Email"
queueUpdate.canned_response_libraries = None
print("Request body: %s", queueUpdate)

try:

#Update the queue
api_response = api_instance.put_routing_queue(queue_id,queueUpdate)
print("Queue updated successfully!")
print(api_response)
except ApiException as e:
print("Exception when calling RoutingApi->put_routing_queue: %s\n" % e)

Log output:-

Raw Body {'acw_settings': None,
'agent_owned_routing': None,
'auto_answer_only': None,
'bullseye': None,
'calling_party_name': None,
'calling_party_number': None,
'conditional_group_routing': None,
'created_by': None,
'date_created': None,
'date_modified': None,
'default_scripts': None,
'description': None,
'direct_routing': None,
'division': None,
'email_in_queue_flow': None,
'enable_audio_monitoring': None,
'enable_manual_assignment': None,
'enable_transcription': None,
'id': None,
'joined_member_count': None,
'media_settings': None,
'member_count': None,
'member_groups': None,
'message_in_queue_flow': None,
'modified_by': None,
'name': None,
'on_hold_prompt': None,
'outbound_email_address': None,
'outbound_messaging_addresses': None,
'peer_id': None,
'queue_flow': None,
'routing_rules': None,
'scoring_method': None,
'self_uri': None,
'skill_evaluation_method': None,
'suppress_in_queue_call_recording': None,
'user_member_count': None,
'whisper_prompt': None}

Request body: %s {'acw_settings': None,
'agent_owned_routing': None,
'auto_answer_only': None,
'bullseye': None,
'calling_party_name': None,
'calling_party_number': None,
'conditional_group_routing': None,
'created_by': None,
'date_created': None,
'date_modified': None,
'default_scripts': None,
'description': None,
'direct_routing': None,
'division': None,
'email_in_queue_flow': None,
'enable_audio_monitoring': None,
'enable_manual_assignment': None,
'enable_transcription': None,
'id': None,
'joined_member_count': None,
'media_settings': None,
'member_count': None,
'member_groups': None,
'message_in_queue_flow': None,
'modified_by': None,
'name': 'TACS_Email',
'on_hold_prompt': None,
'outbound_email_address': None,
'outbound_messaging_addresses': None,
'peer_id': None,
'queue_flow': None,
'routing_rules': None,
'scoring_method': None,
'self_uri': None,
'skill_evaluation_method': None,
'suppress_in_queue_call_recording': None,
'user_member_count': None,
'whisper_prompt': None}

Queue updated successfully!
{'acw_settings': {'timeout_ms': None, 'wrapup_prompt': 'OPTIONAL'},
'agent_owned_routing': None,
'auto_answer_only': False,
'bullseye': None,
'calling_party_name': None,
'calling_party_number': None,
'conditional_group_routing': None,
'created_by': 'a09e7345-64d2-455c-8113-b2828b28fffd',
'date_created': datetime.datetime(2023, 11, 13, 17, 43, 36, 214000, tzinfo=tzutc()),
'date_modified': datetime.datetime(2024, 10, 10, 15, 5, 18, 585000, tzinfo=tzutc()),
'default_scripts': {},
'description': None,
'direct_routing': None,
'division': {'id': 'fc3c4e64-cb11-4b5a-a22a-6ee776387903',
'name': 'Home',
'self_uri': '/api/v2/authorization/divisions/fc3c4e64-cb11-4b5a-a22a-6ee776387903'},
'email_in_queue_flow': None,
'enable_audio_monitoring': None,
'enable_manual_assignment': None,
'enable_transcription': None,
'id': 'bd77dcbc-01b5-4e0e-80c1-515a820ba4d1',
'joined_member_count': 2,
'media_settings': {'call': {'alerting_timeout_seconds': 8,
'auto_answer_alert_tone_seconds': None,
'enable_auto_answer': None,
'manual_answer_alert_tone_seconds': None,
'service_level': {'duration_ms': 20000,
'percentage': 0.8},
'sub_type_settings': None},
'callback': {'alerting_timeout_seconds': 30,
'auto_answer_alert_tone_seconds': None,
'auto_dial_delay_seconds': 300,
'auto_end_delay_seconds': 300,
'enable_auto_answer': None,
'enable_auto_dial_and_end': False,
'manual_answer_alert_tone_seconds': None,
'service_level': {'duration_ms': 20000,
'percentage': 0.8},
'sub_type_settings': None},
'chat': {'alerting_timeout_seconds': 30,
'auto_answer_alert_tone_seconds': None,
'enable_auto_answer': None,
'manual_answer_alert_tone_seconds': None,
'service_level': {'duration_ms': 20000,
'percentage': 0.8},
'sub_type_settings': None},
'email': {'alerting_timeout_seconds': 300,
'auto_answer_alert_tone_seconds': None,
'enable_auto_answer': None,
'manual_answer_alert_tone_seconds': None,
'service_level': {'duration_ms': 86400000,
'percentage': 0.8},
'sub_type_settings': None},
'message': {'alerting_timeout_seconds': 30,
'auto_answer_alert_tone_seconds': None,
'enable_auto_answer': None,
'manual_answer_alert_tone_seconds': None,
'service_level': {'duration_ms': 20000,
'percentage': 0.8},
'sub_type_settings': None}},
'member_count': 3,
'member_groups': None,
'message_in_queue_flow': None,
'modified_by': 'a067522f-642f-4d4b-90e2-ddb422c37011',
'name': 'TACS_Email',
'on_hold_prompt': None,
'outbound_email_address': None,
'outbound_messaging_addresses': None,
'peer_id': None,
'queue_flow': None,
'routing_rules': None,
'scoring_method': 'TimestampAndPriority',
'self_uri': '/api/v2/routing/queues/bd77dcbc-01b5-4e0e-80c1-515a820ba4d1',
'skill_evaluation_method': 'ALL',
'suppress_in_queue_call_recording': False,
'user_member_count': 3,
'whisper_prompt': None}

@Shakti_Joshi Please be sure to handle OAuth client credentials with the same level of security that you would use for any password. I have removed the values from your post above, but you will still need to regenerate the client secret immediately and follow your company's policies for a potential security breach.

1 Like

Hi @Shakti_Joshi

This really looks like you are using an outdated version of the python sdk as it's the only explanation I can think of as to why canned_response_libraries is not showing up since it's definitely part of the api request body. I know you verified you installed the latest version but it's possible your code is pulling from outdated local copy of the sdk somewhere else.

I had a similar problem that was due to my IDE (Pycharm) having an outdated version of the sdk installed thus the version my project was using was outdated.

Regards,
Declan

Thanks Tim, I have regenerated the client secret. I usually take extra care of removing the client secret , but I missed this time.

That may be possible, I am also using pycharm IDE, how did you fix it finally? Just curious to know.

I had to go into the project settings and look at the python interpreter I was using. It should list the packages and their versions being used.

1 Like

Thanks @Declan_ginty - It was indeed pointing to 196.0.0

and I have updated it to 212.0.0

Now we do see an improvement and could see the "canned response" in the request body, and also in the response body set as none, but when I check the queue in Genesys Cloud UI, it still show assigned as "All Libraries"

api_instance = PureCloudPlatformClientV2.RoutingApi(apiclient)
#canned_response_libraries = PureCloudPlatformClientV2.CannedResponseLibraries

"""Define the queue ID"""
queue_id = 0ba4d1'

queueUpdate = PureCloudPlatformClientV2.QueueRequest()
print("Raw Body",queueUpdate)
queueUpdate.name = "Test_Email"
queueUpdate.canned_response_libraries = None
print("Request body: %s", queueUpdate)

try:

#Update the queue
api_response = api_instance.put_routing_queue(queue_id,queueUpdate)
print("Queue updated successfully!")
print(api_response)
except ApiException as e:
print("Exception when calling RoutingApi->put_routing_queue: %s\n" % e)

Here are the logs:-

Raw Body {'acw_settings': None,
'agent_owned_routing': None,
'auto_answer_only': None,
'bullseye': None,
'calling_party_name': None,
'calling_party_number': None,
'canned_response_libraries': None,
'conditional_group_routing': None,
'created_by': None,
'date_created': None,
'date_modified': None,
'default_scripts': None,
'description': None,
'direct_routing': None,
'division': None,
'email_in_queue_flow': None,
'enable_audio_monitoring': None,
'enable_manual_assignment': None,
'enable_transcription': None,
'id': None,
'joined_member_count': None,
'media_settings': None,
'member_count': None,
'member_groups': None,
'message_in_queue_flow': None,
'modified_by': None,
'name': None,
'on_hold_prompt': None,
'outbound_email_address': None,
'outbound_messaging_addresses': None,
'peer_id': None,
'queue_flow': None,
'routing_rules': None,
'scoring_method': None,
'self_uri': None,
'skill_evaluation_method': None,
'suppress_in_queue_call_recording': None,
'user_member_count': None,
'whisper_prompt': None}

Request body: %s {'acw_settings': None,
'agent_owned_routing': None,
'auto_answer_only': None,
'bullseye': None,
'calling_party_name': None,
'calling_party_number': None,
'canned_response_libraries': None,
'conditional_group_routing': None,
'created_by': None,
'date_created': None,
'date_modified': None,
'default_scripts': None,
'description': None,
'direct_routing': None,
'division': None,
'email_in_queue_flow': None,
'enable_audio_monitoring': None,
'enable_manual_assignment': None,
'enable_transcription': None,
'id': None,
'joined_member_count': None,
'media_settings': None,
'member_count': None,
'member_groups': None,
'message_in_queue_flow': None,
'modified_by': None,
'name': 'Test_Email',
'on_hold_prompt': None,
'outbound_email_address': None,
'outbound_messaging_addresses': None,
'peer_id': None,
'queue_flow': None,
'routing_rules': None,
'scoring_method': None,
'self_uri': None,
'skill_evaluation_method': None,
'suppress_in_queue_call_recording': None,
'user_member_count': None,
'whisper_prompt': None}

Queue updated successfully!
{'acw_settings': {'timeout_ms': None, 'wrapup_prompt': 'OPTIONAL'},
'agent_owned_routing': None,
'auto_answer_only': False,
'bullseye': None,
'calling_party_name': None,
'calling_party_number': None,
'canned_response_libraries': None,
'conditional_group_routing': None,
'created_by': 'a09e7345-64d2-455c-8113-b2828b28fffd',
'date_created': datetime.datetime(2023, 11, 13, 17, 43, 36, 214000, tzinfo=tzutc()),
'date_modified': datetime.datetime(2024, 10, 10, 16, 38, 48, 758000, tzinfo=tzutc()),
'default_scripts': {},
'description': None,
'direct_routing': None,
'division': {'id': '387903',
'name': 'Home',
'self_uri': '/api/v2/authorization/divisions/387903'},
'email_in_queue_flow': None,
'enable_audio_monitoring': None,
'enable_manual_assignment': None,
'enable_transcription': None,
'id': 0ba4d1',
'joined_member_count': 2,
'media_settings': {'call': {'alerting_timeout_seconds': 8,
'auto_answer_alert_tone_seconds': None,
'enable_auto_answer': None,
'manual_answer_alert_tone_seconds': None,
'service_level': {'duration_ms': 20000,
'percentage': 0.8},
'sub_type_settings': None},
'callback': {'alerting_timeout_seconds': 30,
'auto_answer_alert_tone_seconds': None,
'auto_dial_delay_seconds': 300,
'auto_end_delay_seconds': 300,
'enable_auto_answer': None,
'enable_auto_dial_and_end': False,
'manual_answer_alert_tone_seconds': None,
'service_level': {'duration_ms': 20000,
'percentage': 0.8},
'sub_type_settings': None},
'chat': {'alerting_timeout_seconds': 30,
'auto_answer_alert_tone_seconds': None,
'enable_auto_answer': None,
'manual_answer_alert_tone_seconds': None,
'service_level': {'duration_ms': 20000,
'percentage': 0.8},
'sub_type_settings': None},
'email': {'alerting_timeout_seconds': 300,
'auto_answer_alert_tone_seconds': None,
'enable_auto_answer': None,
'manual_answer_alert_tone_seconds': None,
'service_level': {'duration_ms': 86400000,
'percentage': 0.8},
'sub_type_settings': None},
'message': {'alerting_timeout_seconds': 30,
'auto_answer_alert_tone_seconds': None,
'enable_auto_answer': None,
'manual_answer_alert_tone_seconds': None,
'service_level': {'duration_ms': 20000,
'percentage': 0.8},
'sub_type_settings': None}},
'member_count': 3,
'member_groups': None,
'message_in_queue_flow': None,
'modified_by': '22c37011',
'name': 'Test_Email',
'on_hold_prompt': None,
'outbound_email_address': None,
'outbound_messaging_addresses': None,
'peer_id': None,
'queue_flow': None,
'routing_rules': None,
'scoring_method': 'TimestampAndPriority',
'self_uri': '/api/v2/routing/queues/0ba4d1',
'skill_evaluation_method': 'ALL',
'suppress_in_queue_call_recording': False,
'user_member_count': 3,
'whisper_prompt': None}

Process finished with exit code 0

Hi,

Could this the same root cause for this post ?

V.P.

Thanks @vpirat , It might be but I am not sure as @Declan_ginty said in his earlier post that he was able to use python sdk to achieve the task.

Unless you guys think it's a similar issue , even at your end.

@Declan_ginty , Can you kindly confirm, if you are able to update the canned response using python sdk, if not then what are the next steps?, if yes, then should I create a support case, or what else can be done to find out why its not updating ?

Warm Regards
Shakti Joshi

Hi @Shakti_Joshi,

I believe the image shown above of the canned response field after update is correct. I checked some other queues that do not have the canned response field set and see the same thing so I believe the queue is being updated correctly and removing the canned response field. If you want to be sure that the queue is updated correctly I would suggest making an api request after the update and checking if canned_response_libraries is set.

Regards,
Declan

Hello @Declan_ginty .... I ran the update query and then ran a get queue, and in the get queue details , I could see that the queue was last updated today, and it does show that "canned response" is set to "none", but in UI it still shows its set to "All":-

Below is the get response query:-

'acw_settings': {'timeout_ms': None, 'wrapup_prompt': 'OPTIONAL'},
'agent_owned_routing': None,
'auto_answer_only': False,
'bullseye': None,
'calling_party_name': None,
'calling_party_number': None,
'canned_response_libraries': None,
'conditional_group_routing': None,
'created_by': '455c',
'date_created': datetime.datetime(2023, 11, 13, 17, 43, 36, 214000, tzinfo=tzutc()),
'date_modified': datetime.datetime(2024, 10, 14, 11, 34, 32, 583000, tzinfo=tzutc()),
'default_scripts': {},
'description': None,
'direct_routing': None,
'division': {'id': '4b5a',
'name': 'Home',
'self_uri': '/api/v2/authorization/divisions/4b5a'},
'email_in_queue_flow': None,
'enable_audio_monitoring': None,
'enable_manual_assignment': None,
'enable_transcription': None,
'id': '80c1',
'joined_member_count': 3,
'media_settings': {'call': {'alerting_timeout_seconds': 8,
'auto_answer_alert_tone_seconds': None,
'enable_auto_answer': None,
'manual_answer_alert_tone_seconds': None,
'service_level': {'duration_ms': 20000,
'percentage': 0.8},
'sub_type_settings': None},
'callback': {'alerting_timeout_seconds': 30,
'auto_answer_alert_tone_seconds': None,
'auto_dial_delay_seconds': 300,
'auto_end_delay_seconds': 300,
'enable_auto_answer': None,
'enable_auto_dial_and_end': False,
'manual_answer_alert_tone_seconds': None,
'service_level': {'duration_ms': 20000,
'percentage': 0.8},
'sub_type_settings': None},
'chat': {'alerting_timeout_seconds': 30,
'auto_answer_alert_tone_seconds': None,
'enable_auto_answer': None,
'manual_answer_alert_tone_seconds': None,
'service_level': {'duration_ms': 20000,
'percentage': 0.8},
'sub_type_settings': None},
'email': {'alerting_timeout_seconds': 300,
'auto_answer_alert_tone_seconds': None,
'enable_auto_answer': None,
'manual_answer_alert_tone_seconds': None,
'service_level': {'duration_ms': 86400000,
'percentage': 0.8},
'sub_type_settings': None},
'message': {'alerting_timeout_seconds': 30,
'auto_answer_alert_tone_seconds': None,
'enable_auto_answer': None,
'manual_answer_alert_tone_seconds': None,
'service_level': {'duration_ms': 20000,
'percentage': 0.8},
'sub_type_settings': None}},
'member_count': 3,
'member_groups': None,
'message_in_queue_flow': None,
'modified_by': '4d4b',
'name': 'TEST_Email',
'on_hold_prompt': None,
'outbound_email_address': None,
'outbound_messaging_addresses': None,
'peer_id': None,
'queue_flow': None,
'routing_rules': None,
'scoring_method': 'TimestampAndPriority',
'self_uri': '/api/v2/routing/queues/80c1',
'skill_evaluation_method': 'ALL',
'suppress_in_queue_call_recording': False,
'user_member_count': 3,
'whisper_prompt': None}

Below is the screenshot showing its still showing "All Libraries"