HOW TO
In some cases, it is necessary to determine the dependencies between Portal for ArcGIS items. For example, in data cleanup, a web app and its associated web map may need to be deleted. Manually checking these dependencies can be tedious. As an alternative, this process can be performed programmatically with the Administrator privilege using the following ArcGIS API for Python functions: dependent_upon() and dependent_to().
The following steps describe how to find dependencies in Portal for ArcGIS using the ArcGIS API for Python.
from arcgis.gis import GIS from IPython.display import display
source = GIS("<portalurl>", "<admin_user>", "<admin_password>") source_users = source.users.search(query=None, sort_field='username', sort_order='asc', max_users=100, outside_org=False, exclude_system=True) source_items_by_id = {} print('User list: Role')
for user in source_users: print(user.username + "\t:\t" + str(user.role))
for user in source_users: num_items = 0 num_folders = 0 print("Collecting item ids for {}".format(user.username), end="\n\n") user_content = user.items()
for item in user_content: num_items += 1 source_items_by_id[item.itemid] = item print("\n\n Item: \t {2} \t\t\t id {0} is dependent on these items: \t {1}".format(item.itemid,item.dependent_upon(), item.title)) if (item.dependent_to()['total'] > 0): print("\t This item is also a dependency of these items: {}".format(item.dependent_to()))
folders = user.folders for folder in folders: num_folders += 1 folder_items = user.items(folder=folder['title']) for item in folder_items: num_items += 1 source_items_by_id[item.itemid] = item print("\n\n Item: \t {2} \t\t\t id {0} is dependent on these items: \t {1}".format(item.itemid,item.dependent_upon(), item.title)) if (item.dependent_to()['total'] > 0): print("\t This item is also a dependency of these items: {}".format(item.dependent_to())) print("Number of folders {} # Number of items {} # Number of users {}".format(str(num_folders), str(num_items), len(source_users)))
The following shows the full script:
from arcgis.gis import GIS from IPython.display import display source = GIS("https://test.domain.com/portal", "portaladmin", "portaladmin") source_users = source.users.search(query=None, sort_field='username', sort_order='asc', max_users=100, outside_org=False, exclude_system=True) source_items_by_id = {} print('User list: Role') for user in source_users: print(user.username + "\t:\t" + str(user.role)) for user in source_users: num_items = 0 num_folders = 0 print("Collecting item ids for {}".format(user.username), end="\n\n") user_content = user.items() for item in user_content: num_items += 1 source_items_by_id[item.itemid] = item print("\n\n Item: \t {2} \t\t\t id {0} is dependent on these items: \t {1}".format(item.itemid,item.dependent_upon(), item.title)) if (item.dependent_to()['total'] > 0): print("\t This item is also a dependency of these items: {}".format(item.dependent_to())) folders = user.folders for folder in folders: num_folders += 1 folder_items = user.items(folder=folder['title']) for item in folder_items: num_items += 1 source_items_by_id[item.itemid] = item print("\n\n Item: \t {2} \t\t\t id {0} is dependent on these items: \t {1}".format(item.itemid,item.dependent_upon(), item.title)) if (item.dependent_to()['total'] > 0): print("\t This item is also a dependency of these items: {}".format(item.dependent_to())) print("Number of folders {} # Number of items {} # Number of users {}".format(str(num_folders), str(num_items), len(source_users)))
Get help from ArcGIS experts
Download the Esri Support App