Genesys Cloud - Developer Community!

 View Only

Sign Up

  • 1.  How can I add a user to a queue using the Genesys Cloud Python APIs?

    Posted 10-08-2025 15:16

    Hi everyone.
    I'm trying to add a user to a queue using the Genesys Cloud APIs and Python.

    I read in the documentation that the patch_user_queue method should be used, and I'm using the code found in the API documentation (https://developer.genesys.cloud/devapps/api-explorer#patch-api-v2-users--userId--queues--queueId-)

    The code I'm using is this:

    api_client = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token(GENESYS_CLOUD_CLIENT_ID, GENESYS_CLOUD_CLIENT_SECRET)

    api_instance = PureCloudPlatformClientV2.UsersApi(api_client)

    queue_id = 'a6e*****-****-4**0-a**5-5************0'
    user_id='14######-9##1-4###-8926-2##########2'

    body = PureCloudPlatformClientV2.UserQueue()
    body.id='a6e*****-****-4**0-a**5-5**********0'
    body.joined=True

    api_response = api_instance.patch_user_queue(queue_id, user_id, body)

    But I always get the following error:

    HTTP response body: {"message":"The server encountered an unexpected condition which prevented it from fulfilling the request.",
    "code":"internal.server.error","status":500,"contextId":"9*******f-####-####-####-4##########2","details":[],"errors":[]}

    I think the problem is the body object I'm passing to the function patch_user_queue, but I don't understand how it should be valued.

    Can anyone help me?
    Thank you so much.


    #PlatformAPI

    ------------------------------
    Giampy
    ------------------------------


  • 2.  RE: How can I add a user to a queue using the Genesys Cloud Python APIs?
    Best Answer

    Posted 10-09-2025 03:19
    Hello,

    Your code is correct to join or unjoin a user from a queue (a queue that the user is already a member of).
    The PATCH /api/v2/users/{userId}/queues/{queueId} enpoint that you are using is only to activate or deactivate a queue for a user. This relates to this functionality: https://help.mypurecloud.com/articles/choose-queues-work/
    As you get a 500 back, I assume that what you are trying to do is to add a user as a member of a queue ( https://help.mypurecloud.com/articles/add-members-to-the-queue/ ).
    You can use the POST /api/v2/routing/queues/{queueId}/members endpoint to add one or multiple members to a queue.
    Code would look like this (for a single user):
    api_instance = PureCloudPlatformClientV2.RoutingApi(api_client);
    queue_id = 'a6e*****-****-4**0-a**5-5**********0'
    first_user = PureCloudPlatformClientV2.WritableEntity()
    first_user.id = 14######-9##1-4###-8926-2##########2'
    body = [first_user] # list[WritableEntity] | Queue Members
    delete = False # bool | True to delete queue members (optional) (default to False)
    api_instance.post_routing_queue_members(queue_id, body, delete=delete)
    Regards,


    ------------------------------
    Jerome Saint-Marc
    Senior Development Support Engineer
    ------------------------------



  • 3.  RE: How can I add a user to a queue using the Genesys Cloud Python APIs?

    Posted 10-09-2025 04:00
    Edited by Giampiero Casu 10-09-2025 04:02

    Hi Jerome, thank you so much, your code works perfectly!
    Thanks to your support, I solved the problem. Thanks again :)

    Can I ask you something else, please?
    How can I find the ID of a queue using the API and Python if I know its name?

    For example, the queue name is "TEST_QUEUE_10." What API call (Python) can I use to find its ID?

    Using the Genesys Cloud API and Python.

    Thank you so much if you can help me.

    Bye, and thanks again for your support.



    ------------------------------
    Giampy
    ------------------------------



  • 4.  RE: How can I add a user to a queue using the Genesys Cloud Python APIs?

    Posted 10-09-2025 04:55

    Hello,

    You can use the GET /api/v2/routing/queues endpoint, using the name parameter to specify/search for your queue based on its name.

    I haven't tested the following code this time but guess it should work:

    api_instance = PureCloudPlatformClientV2.RoutingApi(api_client)
    page_number = 1 # int | Page number (optional) (default to 1)
    page_size = 25 # int | Page size (optional) (default to 25)
    sort_order = 'asc' # str | Note: results are sorted by name. (optional) (default to 'asc')
    name = 'TEST_QUEUE_10' # str | Include only queues with the given name (leading and trailing asterisks allowed) (optional)

    api_response = api_instance.get_routing_queues(page_number=page_number, page_size=page_size, sort_order=sort_order, name=name)
    Regards,


    ------------------------------
    Jerome Saint-Marc
    Senior Development Support Engineer
    ------------------------------



  • 5.  RE: How can I add a user to a queue using the Genesys Cloud Python APIs?

    Posted 10-09-2025 05:32
    Edited by Giampiero Casu 10-09-2025 05:33

    Hi, it works perfectly, thank you so much!

    You were very professional and very kind.

    Thanks again.
    Regards



    ------------------------------
    Giampy
    ------------------------------