3

I'm looking for a way to retrieve the meta for a deleted item(file/folder). I'm able to get change logs indicating that a certain action has been performed on an Item, and I've been able to retrieve the Item itself as well if it hasn't been deleted.

The problem arises when this item gets deleted. In that case, I only know the ID of the Item and when I query the Item itself, I get a 404 (saying object has been deleted).

Recently, I read the following posts

It says a deleted item goes to user's recycle bin where it can be restored or deleted permanently. If deleted from recycle bin it goes to Site Collection Recycle Bin, where an Admin can restore or delete it permanently. So, I'm now looking for a way to access the Recycle Bin for a user and also the Site collection's recycle bin through the REST API.

Though I'm aware of the Recycle Bin endpoints mentioned here but they don't work for me as I keep getting an empty array even though I have a couple files/folders present in the recycle bin(user's recycle bin). I might be missing some configuration/setting?

I have 2 goals;

  • Find a file(the one deleted) in user's recycle bin. (/perosonal/abc_tenant_onmicrosoft_com)
  • If it isn't there, then look for the file in Site Collection's recycle bin.

Both of these through the REST API.

Much appreciated!

Syed Mauze Rehan
  • 1,125
  • 14
  • 31

2 Answers2

3

Recycle Bin resource endpoint URI:

http://<sitecollection>/<site>/_api/web/RecycleBin(recyclebinitemid)

How to distinguish Recycle Bin items

Recycle Bin resource exposes SP.RecycleBinItem.itemType property that returns the type of the Recycle Bin item.

Examples

The following query demonstrates how return File items:

http://<onedrive for business url>/_api/web/RecycleBin?$filter=(ItemType eq 1)

and the the following one how to return Folder items:

http://<onedrive for business url>/_api/web/RecycleBin?$filter=(ItemType eq 5)

,where token <onedrive for business url> for OneDrive For Business site has the following format:

https://tenant-my.sharepoint.com/personal/username_tenant_onmicrosoft_com
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193
  • Thanks. I'll try this tomorrow(first thing!). Will update here! – Syed Mauze Rehan Sep 11 '14 at 20:05
  • When I try to query it gives me an empty array. Although there are items in the Recycle Bin. Furthermore (which is strange btw) when I tried to check if the deleted item was in the Admin's recycle bin (refer to >>> http://community.office365.com/en-us/f/154/t/240959.aspx) There was nothing there. So, first, a deleted item was in My recycle bin and it was giving nothing in the call, and second, the Admin UI(Site Collection Adminitration>> Recycle Bin) wasn't showing that deleted item (you can refer to that link i gave). Is there some permission issue? – Syed Mauze Rehan Sep 13 '14 at 09:43
  • This is what I'm getting >>> { "d": { "results": [] } } – Syed Mauze Rehan Sep 13 '14 at 09:45
  • Just to clear things, I wasn't getting the info for the deleted file even though the item(file) was in My Recycle Bin. And when I couldn't retrieve the item, I deleted it to see if it's really going to the Site Collection Administration/Recycle Bin. And it wasn't there even. I mixed the two in my previous comment, thought I should clear it. – Syed Mauze Rehan Sep 13 '14 at 10:00
  • When the item is being deleted from web it moved to site recycle bin, in case of One Drive for Business site is located here: https://tenant-my.sharepoint.com/personal/username_tenant_onmicrosoft_com – Vadim Gremyachev Sep 13 '14 at 10:25
  • Please make sure you are using the proper url for One Drive for Business site as I mentioned in my answer.. it seems to me the question is about where recycle bin is located but not about what was asked in question – Vadim Gremyachev Sep 13 '14 at 10:30
  • Can I access the Site Collection Administration Recycle Bin? The one accessible through UI by this URL >>> https://tenant-my.sharepoint.com/personal/my_user_my_domain_onmicrosoft_com/_layouts/15/start.aspx#/_layouts/15/AdminRecycleBin.aspx ... How can I access that Recycle Bin through the REST API for Sharepoint? – Syed Mauze Rehan Sep 20 '14 at 10:00
1

Does

http://<sitecollection>/<site>/_api/web/RecycleBin(recyclebinitemid) 

work? I grabbed the structure from: SP.RecycleBinItem.restore Method (sp.js).

Mimi Gentz
  • 1,628
  • 10
  • 14
  • Actually, I'm interested in getting the meta for the Item. Say you added(uploaded) a file, edited it and then deleted it. When I get the changelogs, I get events indicating diff actions performed on an item. When I try to get the meta for this item, I get a 404 (object has been deleted). Now I'm interested in finding out if I could access the recycle bin for the site collection(get the meta for items in recycle bin), through which I could then find out the item using its Id and find out what it was... Because right now, its just an Item, I don't know if it's a file or folder or whatever. – Syed Mauze Rehan Sep 11 '14 at 16:57
  • I don't know the answer to that. Sorry! – Mimi Gentz Sep 11 '14 at 19:18