Apr-10-2024, 03:09 PM
(This post was last modified: Apr-10-2024, 06:38 PM by deanhystad.)
To retrieve all items from the recycle bin on SharePoint, including those deleted by other users, you can modify your code to use SharePoint's administrative APIs. Here's an updated version of your _get_item_information_from_recycle_bin function that uses administrative privileges to access the recycle bin:
def _get_all_items_from_recycle_bin(self, s, SHAREPOINT_SITE): selected_results = None recycle_bin_endpoint = f"{SHAREPOINT_SITE}/_api/site/recyclebin" if s is not None: try: headers = {'accept': 'application/json;odata=verbose'} response = s.get(recycle_bin_endpoint, headers=headers) 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 the recycle bin') else: print("Error code: %s", str(response.status_code)) except Exception as ex: print('Error occurred: %s', ex) else: print('Connection is None!') return selected_results[/python]