Genesys Cloud - Developer Community!

 View Only

Sign Up

  • 1.  get_user_queues Returns Empty Entities

    Posted 05-29-2025 08:03
    Edited by Ramsha Shaikh 05-29-2025 08:05

    Hello,

    I'm working on retrieving queue information for a specific user_id using the Genesys Cloud Python SDK. However, I'm encountering an issue where the get_user_queues method returns an empty list of entities, even though the same request returns data in the API Explorer.

    Here's the Python code I'm using:

    import PureCloudPlatformClientV2
    from PureCloudPlatformClientV2.rest import ApiException
    from pprint import pprint
    import os
    from dotenv import load_dotenv
    load_dotenv()
    
    region = PureCloudPlatformClientV2.PureCloudRegionHosts.us_east_1
    PureCloudPlatformClientV2.configuration.host = region.get_api_host()
    
    
    CLIENT_ID = os.getenv("GENESYS_CLOUD_CLIENT_ID")
    CLIENT_SECRET = os.getenv("GENESYS_CLOUD_CLIENT_SECRET")
    
    a = PureCloudPlatformClientV2.api_client.ApiClient()
    apiclient = a.get_client_credentials_token(CLIENT_ID, CLIENT_SECRET)
    users_api = PureCloudPlatformClientV2.UsersApi(api_client=apiclient)
    
    user_id = 'user_example_id'
    
    
    try:
        api_response = users_api.get_user_queues(user_id)
        pprint(api_response)
    
    except ApiException as e:
        print("Exception when calling UsersApi->get_user_queues: %s\n" % e)

    {
      "entities": [],
      "first_uri": "/api/v2/users/user_id/queues?pageSize=25&pageNumber=1",
      "last_uri": "/api/v2/users/user_id/queues?pageSize=25&pageNumber=1",
      "next_uri": null,
      "page_count": 0,
      "page_number": 1,
      "page_size": 25,
      "previous_uri": null,
      "self_uri": "/api/v2/users/user_id/queues?pageSize=25&pageNumber=1",
      "total": 0
    }

    However, when I use the same user_id in the API Explorer with the same parameters, I receive a list of queues as expected.

    I've verified that my OAuth token has the routing:queue:view permission. I've also tried setting the joined parameter to both True and False, but the result remains the same.

    Am I missing something? Any insights on how to resolve this would be appreciated.

    Thank you


    #PlatformAPI
    #PlatformSDK



  • 2.  RE: get_user_queues Returns Empty Entities

    Posted 05-29-2025 10:30

    Hi @Ramsha Shaikh!

    I assume the API is /api/v2/users{userId}/queues

    Have you tried building a query in something such as Postmaster, using your oAuth credentials to see if that returns anything? This will confirm the oAuth is OK and has necessary permissions. Postmaster helps me all the time to iron out and eliminate some possibilities.

    I am no Python master, but a couple things I would check otherwise would be ensuring your environment is set correctly. 

    You're setting PureCloudPlatformClientV2.configuration.host = region.get_api_host(). While us_east_1 is a valid region, it's crucial to ensure that your Genesys Cloud org actually resides in that region. If your org is in eu_west_1 (Ireland) or ap_southeast_2 (Sydney), but your code connects to us_east_1, you'll get empty results or errors because the data isn't there.

    Another thing would be how are you calling the API?  https://api.mypurecloud.com/api/v2/users{userId}/queues I assume? I know the host is different based on region. For instance I am EU-West-2 so my host is https://api.euw2.pure.cloud



    ------------------------------
    Dale Wylie
    GCX-GCP
    Unified Communications Engineer
    Holcim UK (formally Aggregate Industries UK)
    ------------------------------



  • 3.  RE: get_user_queues Returns Empty Entities

    Posted 05-29-2025 10:39

    Hi Dale,

    Thank you for your reply,

    I'm using the Python SDK to perform the queries, so I'm not calling the API directly but rather using the SDK-provided methods.

    The region and credentials are correct, as I've been able to successfully execute other functions such as:

    • get_license_users

    • get_assistant_queues



    ------------------------------
    Ramsha Shaikh
    Telecom/AI Engineer
    Newfold Digital
    ------------------------------



  • 4.  RE: get_user_queues Returns Empty Entities

    Posted 05-29-2025 10:53

    Ah! My apologies I misunderstood!

    OK what about adding some diagnostic prints in? Of course make sure you update the 'user_example_is' with a read User ID that you know is a member of queues.

    import PureCloudPlatformClientV2
    from PureCloudPlatformClientV2.rest import ApiException
    from pprint import pprint
    import os
    from dotenv import load_dotenv
    
    load_dotenv()
    
    # --- 1. Verify Region Configuration ---
    # Print the region being used
    region_name = os.getenv("GENESYS_CLOUD_REGION", "us_east_1") # Assuming you might set this in .env or default
    print(f"Attempting to connect to region: {region_name}")
    
    try:
        # Use the correct region class dynamically if possible, or ensure it's hardcoded to your org's region
        # For example, if your org is in EU West (Ireland):
        # region = PureCloudPlatformClientV2.PureCloudRegionHosts.eu_west_1
        
        # Or, if you want to be dynamic from .env (make sure it's a valid region host string)
        if region_name == "us_east_1":
            region = PureCloudPlatformClientV2.PureCloudRegionHosts.us_east_1
        elif region_name == "eu_west_1":
            region = PureCloudPlatformClientV2.PureCloudRegionHosts.eu_west_1
        # Add more elif for other regions as needed
        else:
            print(f"Warning: Region '{region_name}' not explicitly handled, defaulting to us_east_1.")
            region = PureCloudPlatformClientV2.PureCloudRegionHosts.us_east_1 # Fallback
    
        PureCloudPlatformClientV2.configuration.host = region.get_api_host()
        print(f"Configured API Host: {PureCloudPlatformClientV2.configuration.host}")
    
    except AttributeError as e:
        print(f"Error setting region: {e}. Make sure the region name in .env (if any) is correct.")
        # You might want to exit here or handle the error appropriately
    
    CLIENT_ID = os.getenv("GENESYS_CLOUD_CLIENT_ID")
    CLIENT_SECRET = os.getenv("GENESYS_CLOUD_CLIENT_SECRET")
    
    if not CLIENT_ID or not CLIENT_SECRET:
        print("Error: GENESYS_CLOUD_CLIENT_ID or GENESYS_CLOUD_CLIENT_SECRET not found in .env")
        exit() # Exit if credentials are missing
    
    # --- Get Auth Token ---
    try:
        a = PureCloudPlatformClientV2.api_client.ApiClient()
        apiclient = a.get_client_credentials_token(CLIENT_ID, CLIENT_SECRET)
        print("Successfully obtained OAuth token.")
    except ApiException as e:
        print(f"Exception when getting OAuth token: {e}")
        print("Please check CLIENT_ID and CLIENT_SECRET.")
        exit() # Exit if authentication fails
    
    users_api = PureCloudPlatformClientV2.UsersApi(api_client=apiclient)
    
    # --- 2. Verify user_id ---
    user_id = 'user_example_id' # <-- **IMPORTANT: Replace with a REAL user ID from your Genesys Cloud org**
    # Print the user_id being used
    print(f"Attempting to fetch queues for user ID: '{user_id}'")
    
    try:
        # You can also try setting joined=True explicitly to see if it makes a difference,
        # though it defaults to True.
        api_response = users_api.get_user_queues(user_id, joined=True)
        
        print("\nAPI Response:")
        pprint(api_response)
    
        if not api_response.entities:
            print(f"\nNo queues found for user ID '{user_id}'.")
            print("Possible causes:")
            print("  1. User is not actually assigned to any queues (check Genesys Cloud UI).")
            print("  2. Incorrect region configuration (see 'Configured API Host' above).")
            print("  3. The provided user_id is incorrect or doesn't exist.")
        else:
            print(f"\nSuccessfully retrieved {len(api_response.entities)} queues for user ID '{user_id}'.")
    
    
    except ApiException as e:
        print("Exception when calling UsersApi->get_user_queues: %s\n" % e)
        # Print the full exception details to get more info
        print(f"Status: {e.status}")
        print(f"Reason: {e.reason}")
        print(f"Headers: {e.headers}")
        print(f"Body: {e.body}")

    You should get some output to check:

    Attempting to connect to region: Does this match your Genesys Cloud org region? (e.g. us_east_1)
    Configured API Host: Does this hostname look correct for your region (e.g. api.mypurecloud.com)
    Attempting to fetch queues for user ID: Is the 'user_id' printed here exactly what you expect, without any typos/abnormalities etc?

    If you do run this, let me know the output if you are unable to see anything wrong if you'd like and I will try to assist.



    ------------------------------
    Dale Wylie
    GCX-GCP
    Unified Communications Engineer
    Holcim UK (formally Aggregate Industries UK)
    ------------------------------



  • 5.  RE: get_user_queues Returns Empty Entities

    Posted 05-29-2025 12:06

    Thank you so much for the detailed code!

    I executed it, but it returns "No queues found for user ID" because the entities array is empty. However, I've confirmed that the user does have queues assigned. I suspect the most probable cause might be permission issues - I'll experiment with that and see if it resolves the problem.

    Thanks again for your help!



    ------------------------------
    Ramsha Shaikh
    Telecom/AI Engineer
    ------------------------------



  • 6.  RE: get_user_queues Returns Empty Entities

    Posted 05-29-2025 12:10

    No problem at all! Please do let me know how you get on. It will be interesting to know what you find!



    ------------------------------
    Dale Wylie
    GCX-GCP
    Unified Communications Engineer
    Holcim UK (Formally Aggregate Industries UK)
    ------------------------------



  • 7.  RE: get_user_queues Returns Empty Entities

    Posted 05-29-2025 12:52

    Hi Ramsha,

    Verify that the queues are not assigned to a division that your client credential grant and the assigned role can access.  Often, when people encounter this issue, their user ID can view the division and its underlying objects, but then, when they create a client credential grant, they don't allow the role to see that division. As a result, when they query the API, it comes back with an empty set.  Remember that divisions control what can be viewed by a user, including objects that can be retrieved.

    Thanks,
         John



    ------------------------------
    John Carnell
    Director, Developer Engagement
    ------------------------------



  • 8.  RE: get_user_queues Returns Empty Entities

    Posted 05-30-2025 05:49
    Edited by Dale Wylie 05-30-2025 05:49

    Excellent point, John - The divisions did not even cross my mind! It does seem like a potentially obvious issue!



    ------------------------------
    Dale Wylie
    GCX-GCP
    Unified Communications Engineer
    Holcim UK (Formally Aggregate Industries UK)
    ------------------------------



  • 9.  RE: get_user_queues Returns Empty Entities

    Posted 06-12-2025 12:31

    Hi all,
    Apologies for the late reply. The issue turned out to be related to permissions on the OAuth Client. I wasn't able to pinpoint the exact permission, as the non-working setup had a Super Admin role, while the working one had a Master Admin role. However, it worked once that role was assigned.

    Thank you @Dale Wylie and @John Carnell for your time and input, and again, sorry for the delay in getting back to you.



    ------------------------------
    Ramsha Shaikh
    Telecom/AI Engineer
    ------------------------------