Hi Everyone,
I work in a one-man GIS team, and one of my main tasks is processing data collected via Field Maps. Once the field workers sync their data collection devices, I process multiple feature classes into a new hosted feature service in AGOL.
Throughout my scripts process it checks if certain feature services exist and if they do to delete them. With the new recycle bin feature my script fails because it is not "permanently deleted" it is just hanging out in the recycle bin. I can manually navigate to the recycle bin and manually delete it and my script works like it normally does.
Has anyone else experienced something like this? I imagine there must be a way to permanently delete an item in AGOL and have it not enter the recycle bin just deleted.
Solved! Go to Solution.
item delete has a "permanent" parameter available (https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#item).
"Optional boolean. Available in ArcGIS Online, setting to True will permanently delete the item rather than sending it to the recycle bin."
This might be what you are looking for?
item delete has a "permanent" parameter available (https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#item).
"Optional boolean. Available in ArcGIS Online, setting to True will permanently delete the item rather than sending it to the recycle bin."
This might be what you are looking for?
Thank you Justin you are a life saver!
Maybe there is a programmatic way to toggle off the AGOL Recycle bin while you are running your scripts?
4/21/25
I was just able to apply this solution to a new script I had created. Thank you very much.
Has anyone successfully been able to permanently delete an AGOL item via Python AFTER ESRI added the recycle bin?
from arcgis.gis import GIS
gis = GIS("home")
item_id='767ff8fe699047d7bc0e74c0f15a63a4' #this is the service_ID of the hosted feature layer to delete
itemToDelete = gis.content.get(item_id)
itemToDelete.delete(permanent=True)
Running this code in AGOL Notebooks as well as Python 3.9.16 on my computer with Pro 3.1.2 I get the following error message:
TypeError Traceback (most recent call last)
/tmp/ipykernel_19/3146111176.py in <cell line: 7>()
5
6 itemToDelete = gis.content.get(item_id)
----> 7 itemToDelete.delete(permanent=True)
TypeError: delete() got an unexpected keyword argument 'permanent'
I too am seeing: TypeError: delete() got an unexpected keyword argument 'permanent'
I had Python that was deleting items on AGOL and then copying up to AGOL updated like named items. After we turned on the recycle bin the copying up wasn't working anymore since the like named items were in the Recycle Bin. Found this thread but now seeing issues with the 'permanent' option.
I am retrieving the item by name but have also retrieved it by item ID with the same results.
Python 3.9.18 ArcGIS Pro 3.2.0
I was getting the same error trying to use item.delete(permanent=True) in an ArcGIS Notebook @GregHorne, @Tom_Laue. But once I updated my Notebook to use the latest runtime it worked fine and the item is deleted permanently without going anywhere near the recycle bin. The Notebook Runtime setting is on the Setting page of the item in AGOL, I just set it to the most recent version:
Hope this helps.
@Tom_Laue For executing from Python on the desktop, it looks like the issue is that one needs to use arcgis (ArcGIS API for Python) v 2.3.0 which comes with ArcGIS Pro v3.3.0. I tried using Pro v3.1 and v3.2 which comes with arcgis v2.2.0.1.
I am not familiar with cloning Python environments but I did try that with Pro v3.1 and v3.2 and then attempted to update the arcgis package but that did not help. It never upgraded out of v2.2.0.x
Yes, @MappyIan -- that solved my problem.
I wanted to share what I ended up doing.
I'm downloading AGOL hosted feature layers to GDB on a nightly basis (via Python and Task Scheduler).
Every time I do this, it creates a File GDB in AGOL that I used to delete right after it's creation.
Since July 2024, it would now go to the Recycle Bin for 14 days (which consumes credits as these are >1 GB files).
Instead of deleting the File GDB, I modified my script to add a tag to each item: 'ToDelete'
Then in AGOL Notebooks (using Runtime 10), I schedule a script daily to delete content with that tag.
from arcgis.gis import GIS
gis = GIS("home")
def find_items_with_tag(tag):
# Search for items with the specified tag
#items = gis.content.search(query="tags: = 'ToDelete'", max_items=100 )
items = gis.content.search(query="tags: = 'ToDelete'",item_type="File Geodatabase", max_items=300 )
# Extract and return the global IDs of the found items
global_ids = [item.id for item in items]
return global_ids
if __name__ == "__main__":
tag_to_search = "ToDelete"
item_ids_list = find_items_with_tag(tag_to_search)
print("Global IDs of items with tag '{}':".format(tag_to_search))
for item_id in item_ids_list:
print(item_id )
itemToDelete = gis.content.get(item_id)
itemToDelete.delete(permanent=True)