Migrating Objects from one Org to another Org using Python SDK

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.

How to assign IDs for the Divisions in Target environment?

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

Thank you,
Becky

1 Like

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

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 source_data[i].name == target_divisions[i].name:

    division_body.name = target_divisions[i].name

    division_body.id = target_divisions[i].id

    div = map_divisions.put_authorization_division(target_division_ids[i], division_body[i])

for i in range(len(source_data)):

if source_data[i].name not in target_queue_list:

    body.division = body.division_body[division_body]

    body.name = source_data[i].name

    body.id = None

    body.id = source_data[i].id

    body.auto_answer_only = source_data[i].auto_answer_only

    body.enable_transcription = source_data[i].enable_transcription

    body.acw_settings = source_data[i].acw_settings

    body.calling_party_name = source_data[i].calling_party_name

    body.calling_party_number = source_data[i].calling_party_number

    body.media_settings = source_data[i].media_settings

    body.routing_rules = source_data[i].routing_rules

    body.skill_evaluation_method = source_data[i].skill_evaluation_method

    body.whisper_prompt = source_data[i].whisper_prompt

response = create_queue.post_routing_queues(body)

print(response)

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

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
SOURCE_CLIENT_ID = 'xxxxx'
SOURCE_CLIENT_SECRET = 'xxxxx'
SOURCE_REGION = PureCloudPlatformClientV2.PureCloudRegionHosts.us_east_1

# Client Credentials for the TARGET Genesys Cloud org
TARGET_CLIENT_ID = 'xxxxx'
TARGET_CLIENT_SECRET = 'xxxxx'
TARGET_REGION = PureCloudPlatformClientV2.PureCloudRegionHosts.eu_west_1


def export_queues():
    # Authenticate
    PureCloudPlatformClientV2.configuration.host = SOURCE_REGION.get_api_host()
    api_client = PureCloudPlatformClientV2.api_client.ApiClient() \
        .get_client_credentials_token(SOURCE_CLIENT_ID, SOURCE_CLIENT_SECRET)

    # Get queues from the target org
    routing_api = PureCloudPlatformClientV2.RoutingApi(api_client)
    routing_queues_result = routing_api.get_routing_queues(page_size=500)
    print(f'Total queues exported: {routing_queues_result.total}')

    return routing_queues_result.entities


def import_queues(queues):
    # Authenticate
    PureCloudPlatformClientV2.configuration.host = TARGET_REGION.get_api_host()
    api_client = PureCloudPlatformClientV2.api_client.ApiClient() \
        .get_client_credentials_token(TARGET_CLIENT_ID, TARGET_CLIENT_SECRET)

    authorization_api = PureCloudPlatformClientV2.AuthorizationApi(api_client)
    routing_api = PureCloudPlatformClientV2.RoutingApi(api_client)

    # Get the divisions in the target org
    home_division = authorization_api.get_authorization_divisions_home()
    divisions = authorization_api.get_authorization_divisions().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 division_map:
            queue.division = division_map[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

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


def main():
    queues = export_queues()
    import_queues(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.
1 Like

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