I'm trying to batch delete contents in ArcGIS Online. For example, when users export a feature service to File Geodatabase, there will be a geodatabase object in ArcGIS online before downloading to local folders. I wonder if I can write a script to delete all the file geodatabase objects. I know how to delete a single item using the API like item.delete(). But I don't know how to delete items in a bulk.
I appreciate your help!
Solved! Go to Solution.
There is a function delete_items() that is part of the ContentManager class. Use it like this:
gis = arcgis.GIS('url', 'user', 'pw')
fgdb_list = gis.content.search('', item_type='File Geodatabase', max_items=-1)
gis.content.delete_items(fgdb_list)
It's actually part of the query string, details of which you can find here.
fgdb_list = gis.content.search(query="owner:my-username", item_type='File Geodatabase', max_items=-1)
There is a function delete_items() that is part of the ContentManager class. Use it like this:
gis = arcgis.GIS('url', 'user', 'pw')
fgdb_list = gis.content.search('', item_type='File Geodatabase', max_items=-1)
gis.content.delete_items(fgdb_list)
If I want to delete item created by me only. How do I set the owner parameter in the script? The search function doesn't seem to have a parameter like item owner.
It's actually part of the query string, details of which you can find here.
fgdb_list = gis.content.search(query="owner:my-username", item_type='File Geodatabase', max_items=-1)
Thank you so much, Josh!