To retrieve all items from the recycle bin on SharePoint, including those deleted by other users, you need to adjust the permissions or use an account with higher privileges. By default, a site owner's permissions might restrict them to only see items they have deleted, depending on the site's configuration.
import sharepy
def _auth_sharepy(self, USERNAME, PASSWORD, SITE_URL):
result = None
try:
conn_s = sharepy.connect(SITE_URL, USERNAME, PASSWORD)
result = conn_s
except Exception as ex:
print(f"An error occurred: {ex}")
return result
def _get_item_information_from_recycle_bin(self, s, SHAREPOINT_SITE):
selected_results = None
recycle_bin_endpoint = f"{SHAREPOINT_SITE}/_api/web/RecycleBin"
if s is not None:
try:
response = s.get(recycle_bin_endpoint)
if response.status_code == 200:
results = response.json()['d']['results']
selected_results = [
{
'LeafName': item['LeafName'],
'DirName': item['DirName'],
'ItemType': item['ItemType'],
'DeletedDate': item['DeletedDate'],
'DeletedByEmail': item['DeletedByEmail'],
'Id': item['Id']
} for item in results
]
print('Successfully retrieved items from recycle bin')
else:
print(f"Error code: {response.status_code}")
except Exception as ex:
print(f'Error occurred: {ex}')
else:
print('Connection is None!')
return selected_results