Python Forum
How to get all items in SharePoint recycle bin by using sharepy library in Python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get all items in SharePoint recycle bin by using sharepy library in Python?
#3
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]
Reply


Messages In This Thread
RE: How to get all items in SharePoint recycle bin by using sharepy library in Python? - by SandraYokum - Apr-10-2024, 03:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  sharepoint: Access has been blocked by Conditional Access policies CAD79 0 2,382 Jul-12-2024, 09:36 AM
Last Post: CAD79
  Updating sharepoint excel file odd results cubangt 1 2,182 Nov-03-2023, 05:13 PM
Last Post: noisefloor
  Trying to access excel file on our sharepoint server but getting errors cubangt 0 1,558 Feb-16-2023, 08:11 PM
Last Post: cubangt
  Removal of items in .txt using python nanakochan 8 14,889 Sep-02-2022, 04:58 PM
Last Post: perfringo
  SharePoint Online/365 authentication using .cer file mart79 0 2,801 Nov-08-2020, 03:31 PM
Last Post: mart79
  concatenating 2 items at a time in a python list K11 3 3,437 Oct-21-2020, 09:34 AM
Last Post: buran
  Authentication error when accessing Microsoft SharePoint klllmmm 3 13,028 Jun-10-2020, 07:46 AM
Last Post: nuffink
  how to use items combobox in table name sqlite in python hampython 1 3,595 May-24-2020, 02:17 AM
Last Post: Larz60+
  Access list items in Python kamaleon 2 3,184 Dec-31-2019, 11:10 AM
Last Post: kamaleon
  Pulling data from Sharepoint list gandiswapna0388 1 3,424 Jul-17-2019, 08:35 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020