I'm having problems deleting an item in Portal for ArcGIS. It is delete protected so I can't delete using the UI. I am unable to change the delete protection because the edit button is also disabled. I used ArcGIS Online Assistant and tried to change the delete protection from there but the change from true to false wouldn't actually take. It just kept reverting back. I tried to find the xml or json file in the item ID folder on the Portal server itself, but I couldn't find the delete protection attribute. I'm hesitant to just outright delete the item ID folder itself because I don't know if the item ID is registered anywhere else (a user's item list for instance). Could anyone instruct me on a thorough way to force delete an item from 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]
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
If this helps anyone, you can delete an item via this URL:
https://[your server]/[your portal name]/sharing/rest/content/users/[your username] - This will show you the content you own, then you can click on the item, then delete it. I had to do this for content that was not showing up in Portal for ArcGIS. I knew it was there and went looking for it and found it via the URL above.
Imtiaz Syed - Nice script, thanks for sharing.