Legacy Dev Forum Posts

 View Only

Sign Up

Migrating Objects from one Org to another Org using Python SDK

  • 1.  Migrating Objects from one Org to another Org using Python SDK

    Posted 06-05-2025 18:08

    Komali_Sidagam | 2021-09-17 12:49:32 UTC | #1

    Hi All,

    I have list of Divisions[ids, names] from one Org, now i should copy all these divisions to another Org, how can i achieve this.


    Komali_Sidagam | 2021-09-14 17:48:14 UTC | #2

    How to assign IDs for the Divisions in Target environment?


    Becky_Powell | 2021-09-14 17:54:51 UTC | #3

    Hi Komali, you may assign your own division name - but the system auto-assigns division IDs.

    Thank you, Becky


    Komali_Sidagam | 2021-09-15 06:35:49 UTC | #4

    Thanks Becky. Got it ! One more thing, we need to push Roles with the permissions right, so the policy permissions again has lists of action sets, if i have to push all the Roles with the same permission policies at once, is it possible. . do you have any sample script to refer


    Komali_Sidagam | 2021-09-17 12:54:01 UTC | #5

    Hi All,

    I was trying to create queues in target environment from source and while creating assign queues to its appropriate divisions in target. I'm using python SDK to do so and i am stuck at the division assigning module. We need to search the name of division from source and get the division id from target and need to loop through it. Could some one provide me the sample for that part. the one below is not working.

    mapping divisions to target

    map_divisions = PureCloudPlatformClientV2.AuthorizationApi(apiclient1)

    division_body = PureCloudPlatformClientV2.AuthzDivision()

    for i in range(len(source_data)):

    if sourcedata[i].name == targetdivisions[i].name:

    divisionbody.name = targetdivisions[i].name

    divisionbody.id = targetdivisions[i].id

    div = mapdivisions.putauthorizationdivision(targetdivisionids[i], divisionbody[i])

    for i in range(len(source_data)):

    if sourcedata[i].name not in targetqueue_list:

    body.division = body.divisionbody[divisionbody]

    body.name = source_data[i].name

    body.id = None

    body.id = source_data[i].id

    body.autoansweronly = sourcedata[i].autoanswer_only

    body.enabletranscription = sourcedata[i].enable_transcription

    body.acwsettings = sourcedata[i].acw_settings

    body.callingpartyname = sourcedata[i].callingparty_name

    body.callingpartynumber = sourcedata[i].callingparty_number

    body.mediasettings = sourcedata[i].media_settings

    body.routingrules = sourcedata[i].routing_rules

    body.skillevaluationmethod = sourcedata[i].skillevaluation_method

    body.whisperprompt = sourcedata[i].whisper_prompt

    response = createqueue.postrouting_queues(body)

    print(response)


    John_Carnell | 2021-09-21 20:50:07 UTC | #6

    Hi Komali,

    Could you please elaborate on "It's not working". Are you get an error response or you are just not getting the behavior you are expecting.

    Thanks, John Carnell Manager, Developer Engagement


    anon28885283 | 2021-09-22 10:30:37 UTC | #7

    Hi Komali,

    As John mentioned it would be helpful if you could provide more details on the error you're getting.

    I also made a sample script with basic functionality of importing queues from one org to another which you can refer to in developing your own:

    import time import PureCloudPlatformClientV2

    Client Credentials for the SOURCE Genesys Cloud org

    SOURCECLIENTID = 'xxxxx' SOURCECLIENTSECRET = 'xxxxx' SOURCEREGION = PureCloudPlatformClientV2.PureCloudRegionHosts.useast_1

    Client Credentials for the TARGET Genesys Cloud org

    TARGETCLIENTID = 'xxxxx' TARGETCLIENTSECRET = 'xxxxx' TARGETREGION = PureCloudPlatformClientV2.PureCloudRegionHosts.euwest_1

    def export_queues():

    Authenticate

    PureCloudPlatformClientV2.configuration.host = SOURCEREGION.getapihost() apiclient = PureCloudPlatformClientV2.apiclient.ApiClient() \ .getclientcredentialstoken(SOURCECLIENTID, SOURCECLIENTSECRET)

    Get queues from the target org

    routingapi = PureCloudPlatformClientV2.RoutingApi(apiclient) routingqueuesresult = routingapi.getroutingqueues(pagesize=500) print(f'Total queues exported: {routingqueuesresult.total}')

    return routingqueuesresult.entities

    def import_queues(queues):

    Authenticate

    PureCloudPlatformClientV2.configuration.host = TARGETREGION.getapihost() apiclient = PureCloudPlatformClientV2.apiclient.ApiClient() \ .getclientcredentialstoken(TARGETCLIENTID, TARGETCLIENTSECRET)

    authorizationapi = PureCloudPlatformClientV2.AuthorizationApi(apiclient) routingapi = PureCloudPlatformClientV2.RoutingApi(apiclient)

    Get the divisions in the target org

    homedivision = authorizationapi.getauthorizationdivisionshome() divisions = authorizationapi.getauthorizationdivisions().entities

    Map divisions by name

    division_map = {division.name: division for division in divisions}

    for queue in queues:

    Assign division on the new queue

    if queue.division.name in divisionmap: queue.division = divisionmap[queue.division.name] else: print(f'Queue {queue.name}: {queue.division.name} division is not found, assigning queue to home division') queue.division = home_division

    routingapi.postrouting_queues(queue) print(f'Queue {queue.name}: successfully created') time.sleep(1)

    def main(): queues = exportqueues() importqueues(queues)

    if name == 'main': main()

    A couple of things to note:

    1. The divisions should already be imported in the target org with the exact same name as the divisions from the source org.
    2. The client credentials clients should have permissions to the other divisions. If not, you won't be able to GET or create queues for other divisions other than the Home one.
    3. The sample I made only works for simple queues. If the queues from the source org has other custom configuration like referencing DIDs, or Call flows, recreating that same Queue object in the target org will cause errors.

    system | 2021-10-23 10:31:27 UTC | #8

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 12001