Delete orphaned items from Portal for ArcGIS using python script

1997
1
07-15-2019 04:16 PM
ImtiazSyed
New Contributor III
1 1 1,997

Exact error: Unable to reach the server where the service is. Consider using calling deleteItem with options = { 'force' : true } if the server won't be available anymore.

The issue usually occurs when Portal for ArcGIS is unfederated and re-federated or when some configuration changes are made to Portal for ArcGIS.

import arcgis
from arcgis.gis import GIS
gis = GIS("https://portalname/arcgis", "username", "password")

#get the list of orphaned items
delete_orphaned_items = gis.content.search(query="owner: ownername AND title:*title*", item_type='Feature *', max_items=100)
delete_orphaned_items

#filter the items 
filtered_items = [item for item in delete_orphaned_items if 'title' in item.title]
print(len(filtered_items))
sorted(filtered_items, key=lambda x:x.title)

#replace dry_run with force. dry_run checks if the item can be safely deleted
for item in filtered_items:
    try:
        item.delete(dry_run=True)
    except TypeError:
        print(f'{item.title} not deleted')
    except RuntimeError:
        print(f'{item.title} not deleted')
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Delete an item in Portal for ArcGIS using arcgis.gis module: https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.gis.toc.html#item

1 Comment
About the Author
GIS Developer
Labels