Select to view content in your preferred language

Implement "Empty Recycle Bin" button

170
2
3 weeks ago
Status: Open
LindsayRaabe_FPCWA
MVP Regular Contributor

It would be handy if there was an Empty Recycle Bin button, instead of having to manually select and delete items already in the recycle bin. 

 

We've got nearly 1000 items in the recycle bin after a bit of a python mishap (nothing lost that wasn't supposed to be thankfully), but now to delete all the items permanently, it seems I need to select and delete them in batches of 60 (limit displayed on the Contents page) with no "Select All" option. 

LindsayRaabe_FPCWA_0-1736143412516.png

Also couldn't figure out how to delete from the recycle bin using python. Would be happy to try that out if someone can guide me. 

2 Comments
LindsayRaabe_FPCWA

I think I have found a work around, which is to disable the Recycle Bin, which results in all trash items being permanently deleted, though upon reenabling the bin, those items still appear for some time (guessing there is lag time in the wipe process actually happening - they disappeared after a couple of hours). 

This would however happen across all users and not just "your" recycle bin. 

jdyerLACSD

See arcgis.gis module | ArcGIS API for Python for getting the items in your recycling bin, and then you can iterate through each item to permanently delete them by calling delete() on each item and specifying permanent=True (documentation).  But this only works if the arcgis Python library is upgraded to the latest version.  If you can't upgrade, you can use the REST API to permanently delete an item with the function below, but I haven't explored an alternative way to list the recycling bin contents yet.

def permanentlyDeleteAgolItem(portal: GIS, item_id: str) -> tuple[bool, str]:
    """
    Permanently deletes portal item (instead of sending to Recycling Bin)

    Parameters
    ----------
    portal: arcgis.gis.GIS
        Connection to GIS portal
    item_id: str
        ID of portal item to delete

    Returns
    -------
    success: bool
        Whether deletion was successful
    error: str
        Error message, if any
    """
    portal_url = portal.url
    username = portal.users.me.username
    token = portal._con.token
    data = {"token": token, "items": item_id, "permanentDelete": True, "f": "json"}
    url = f"{portal_url}/sharing/rest/content/users/{username}/deleteItems"
    response = requests.post(url, data=data)
    results = response.json().get("results", [])
    result = results[0]
    success = result.get("success", False)
    error = result.get("message", "")
    return success, error