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?
#1
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
Reply


Messages In This Thread
How to get all items in SharePoint recycle bin by using sharepy library in Python? - by QuangHuynh - Apr-03-2024, 03:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Updating sharepoint excel file odd results cubangt 1 971 Nov-03-2023, 05:13 PM
Last Post: noisefloor
  Trying to access excel file on our sharepoint server but getting errors cubangt 0 882 Feb-16-2023, 08:11 PM
Last Post: cubangt
  Removal of items in .txt using python nanakochan 8 1,938 Sep-02-2022, 04:58 PM
Last Post: perfringo
  SharePoint Online/365 authentication using .cer file mart79 0 2,096 Nov-08-2020, 03:31 PM
Last Post: mart79
  concatenating 2 items at a time in a python list K11 3 2,439 Oct-21-2020, 09:34 AM
Last Post: buran
  Authentication error when accessing Microsoft SharePoint klllmmm 3 10,612 Jun-10-2020, 07:46 AM
Last Post: nuffink
  how to use items combobox in table name sqlite in python hampython 1 2,761 May-24-2020, 02:17 AM
Last Post: Larz60+
  Access list items in Python kamaleon 2 2,439 Dec-31-2019, 11:10 AM
Last Post: kamaleon
  Pulling data from Sharepoint list gandiswapna0388 1 2,670 Jul-17-2019, 08:35 AM
Last Post: perfringo
  Python find the minimum length of string to differentiate dictionary items zydjohn 3 3,765 Mar-03-2018, 05:23 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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