Apr-03-2024, 03:01 AM
I'm trying to retrieve all items from the recycle bin on SharePoint. Below is my code. Currently, I notice that I can only retrieve items deleted by the user used to make authentication. This user is currently the owner of the site. I want to retrieve all items inside the recycle bin, including those deleted by other users. How can I achieve this? Any help from the community would be greatly appreciated. Thank you very much.
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("An error occurred: %s", 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 get items from recycle bin')
else:
print("Error code: %s", str(response.status_code))
except Exception as ex:
print('Error occoured: %s', ex)
else:
print('Connection is None!')
return selected_results
