English

How To: Copy content from the Operations Dashboard of one Portal for ArcGIS or ArcGIS Online account to another using ArcGIS API for Python

Summary

It is common for an organization to have more than one Portal for ArcGIS or ArcGIS Online account for different purposes. For example, an organization may need two accounts, one for internal use and another for public access. In certain cases, the content from one account must be copied to the other. Refer to Portal for ArcGIS: Example: Copy Content for the steps to copy items from Portal for ArcGIS or ArcGIS Online. It is also possible to copy content from Operation Dashboards using ArcGIS API for Python.

Procedure

Follow the steps below to copy content from the Operations Dashboard of one Portal for ArcGIS or ArcGIS Online account to another:

  1. Import the necessary modules.
from arcgis.gis import GIS
from IPython.display import display
from getpass import getpass
  1. Declare input parameters to receive the source URL and credentials.
source_portal = input("Enter Source Portal : ")
if source_portal == "":
    source_portal = "arcgis.com"

source_admin = input("Enter Source Admin Username: ")
source_admin_password = getpass("Enter password: ")
source_owner = input("Enter Source Owner Username: ")
 
Note:
In the console window, specify the Portal for ArcGIS URL as the source_admin for Portal for ArcGIS, or leave it blank by pressing Enter for ArcGIS Online.
  1. Declare input parameters to receive the target URL and credentials.
target_portal = input("Enter Target Portal : ")
if target_portal == "":
    target_portal = "arcgis.com"

target_admin = input("Enter Target Admin Username: ")
target_admin_password = getpass("Enter password: ")
target_owner = input("Enter Target Owner Username: ")
  1. Create a connection to the source and target URL.
source = GIS("https://" + source_portal, source_admin, source_admin_password, verify_cert=False)
target = GIS("https://" + target_portal, target_admin, target_admin_password, verify_cert=False)
print("Connected to Source and Target Portals")
Note:
The script above does not check for certification. If certification is provided and the SSL is fully configured, the code segment, verify_cert can be set to true: verify_cert=True.
 
  1. Search for the owners specified in steps 2 and 3.
source_user = source.users.search(source_owner)
target_user = target.users.search(target_owner)
print("Source User: \t:\t" + source_user[0].username + "\t:\t" + source_user[0].role)
print("Target User: \t:\t" + target_user[0].username + "\t:\t" + target_user[0].role)
  1. Search for all available dashboards under the specified owner in the Source URL.
search_result = source.content.search(query="owner:"+str(source_owner), item_type="Dashboard")
search_result
  1. Iterate the 'create copy to a folder' process for each dashboard found in the target URL.
for item in search_result:
    app=source.content.get(item.id)
    data = [app]
    target.content.clone_items(data, "dashboards", copy_data=True, search_existing_items=False)
    print("copied item successfully: %s" %(app.title))

print("Done")

The following script shows how the full code looks after completing the steps:
    from arcgis.gis import GIS
    from IPython.display import display
    from getpass import getpass
    
    source_portal = input("Enter Source Portal (machine.domain.com/webadaptor...leave blank for ArcGIS Online)")
    if source_portal == "":
        source_portal = "arcgis.com"
    source_admin = input("Enter Source Admin Username: ")
    source_admin_password = getpass("Enter password: ")
    source_owner = input("Enter Source Owner Username: ")
    
    target_portal = input("Enter Target Portal (machine.domain.com/webadaptor...leave blank for ArcGIS Online)")
    if target_portal == "":
        target_portal = "arcgis.com"
    target_admin = input("Enter Target Admin Username: ")
    target_admin_password = getpass("Enter password: ")
    target_owner = input("Enter Target Owner Username: ")
    
    source = GIS("https://" + source_portal, source_admin, source_admin_password, verify_cert=False)
    target = GIS("https://" + target_portal, target_admin, target_admin_password, verify_cert=False)
    print("Connected to Source and Target Portals")
    
    source_user = source.users.search(source_owner)
    target_user = target.users.search(target_owner)
    print("Source User: \t:\t" + source_user[0].username + "\t:\t" + source_user[0].role)
    print("Target User: \t:\t" + target_user[0].username + "\t:\t" + target_user[0].role)
    
    search_result = source.content.search(query="owner:"+str(source_owner), item_type="Dashboard")
    search_result
    
    for item in search_result:
        app=source.content.get(item.id)
        data = [app]
        target.content.clone_items(data, "dashboards", copy_data=True, search_existing_items=False)
        print("copied item successfully: %s" %(app.title))
    
    print("Done")

     

    Related Information