I need an API (ideally just a single API call that can accomplish this) that ultimately allows me to determine if, for a given queue, do I have any agents at all that are on-queue AND have a specific ACD skill.
The business logic will redirect the interaction to a different queue if there are no agents on-queue with the required skill (this last part is critical). I can easily determine how many agents are on-queue in general - I have that set up already. But that doesn't tell me if any of those on-queue agents also have the necessary skill for a given interaction.
Just need to be pointed to the right API to use for this with the hope that there's a single API call that would return either a list of agents who have the skill or a count of agents who have the skill (and are also on-queue).
Here is a Python script that will go through each queue and then try to find all the agents who are online for that queue with that skill set.
It probably won't meet your exact needs but it demonstrates the API in action. Please note you need to install two libraries to use the script: pip install prettytable pip install PureCloudPlatformClientV2
The script is as-is and it's your responsibility to test it and modify it (No guarantees or warranties):
import os
import argparse
import PureCloudPlatformClientV2
from PureCloudPlatformClientV2.rest import ApiException
from prettytable import PrettyTable
def main():
# Set up command-line argument parsing
parser = argparse.ArgumentParser(description="Find agents on-queue with a specific skill across all queues.")
parser.add_argument('skill_name', type=str, help='The name of the skill to search for.')
args = parser.parse_args()
# Retrieve environment variables
client_id = os.getenv('GENESYSCLOUD_OAUTHCLIENT_ID')
client_secret = os.getenv('GENESYSCLOUD_OAUTHCLIENT_SECRET')
environment = os.getenv('GENESYSCLOUD_API_REGION')
# Validate environment variables
if not all([client_id, client_secret, environment]):
print("Error: Missing one or more environment variables: "
"GENESYSCLOUD_OAUTHCLIENT_ID, GENESYSCLOUD_OAUTHCLIENT_SECRET, GENESYSCLOUD_API_REGION")
return
# Configure the SDK
PureCloudPlatformClientV2.configuration.host = environment
api_client = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token(client_id, client_secret)
# Create instances of the necessary APIs
routing_api = PureCloudPlatformClientV2.RoutingApi(api_client)
users_api = PureCloudPlatformClientV2.UsersApi(api_client)
try:
# Retrieve all routing skills to map skill names to IDs
skills = routing_api.get_routing_skills()
skill_map = {skill.name: skill.id for skill in skills.entities}
# Check if the specified skill exists
if args.skill_name not in skill_map:
print(f"Skill '{args.skill_name}' not found.")
return
required_skill_id = skill_map[args.skill_name]
# Initialize the table
table = PrettyTable()
table.field_names = ["Queue ID", "Queue Name", "Skill ID", "Skill Name", "User ID", "User Name"]
# Initialize pagination variables for queues
page_number = 1
page_size = 100 # Maximum page size
more_pages = True
while more_pages:
# Fetch a page of queues
queues = routing_api.get_routing_queues(page_size=page_size, page_number=page_number)
queue_list = queues.entities
# Iterate through each queue
for queue in queue_list:
queue_id = queue.id
queue_name = queue.name
# Initialize pagination variables for queue members
member_page_number = 1
more_member_pages = True
while more_member_pages:
# Fetch a page of queue members with expanded skills and presence information
members = routing_api.get_routing_queue_members(
queue_id=queue_id,
page_size=page_size,
page_number=member_page_number,
expand=['skills', 'routingStatus','presence'],
joined=True
)
# Filter members who are on-queue and have the exact required skill
for member in members.entities:
if any(skill.id == required_skill_id for skill in member.user.skills) and member.user.presence.presence_definition.system_presence=="On Queue":
# Fetch user details
user = users_api.get_user(member.id)
# Add row to the table
table.add_row([queue_id, queue_name, required_skill_id, args.skill_name, user.id, user.name])
# Check if there are more pages of members
member_page_number += 1
more_member_pages = (members.next_uri!=None)
# Check if there are more pages of queues
page_number += 1
more_pages = page_number <= queues.page_count
# Print the table
print(table)
except ApiException as e:
print(f"Exception when calling API: {e}")
if __name__ == '__main__':
main()
Thanks,
John Carnell
Director, Developer Engagement