{"id":2267,"date":"2023-11-07T12:09:37","date_gmt":"2023-11-07T11:09:37","guid":{"rendered":"https:\/\/blog.kodono.info\/wordpress\/?p=2267"},"modified":"2023-11-07T12:09:37","modified_gmt":"2023-11-07T11:09:37","slug":"search-and-restore-an-item-from-a-sharepoint-online-recycle-bin","status":"publish","type":"post","link":"https:\/\/blog.kodono.info\/wordpress\/2023\/11\/07\/search-and-restore-an-item-from-a-sharepoint-online-recycle-bin\/","title":{"rendered":"Search and restore an item from a SharePoint Online Recycle Bin"},"content":{"rendered":"<p>It might be difficult to search for an item in a SharePoint recycle bin. I was using the end point <code>_api\/site\/RecycleBin<\/code> as a <b>Site Collection Administrator<\/b>, but in some cases it returns an error &#8220;The attempted operation is prohibited because it exceeds the list view threshold.&#8221;.<\/p>\n<p>The solution is to use another end point <code>_api\/site\/getrecyclebinitems<\/code> (<a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/microsoft.sharepoint.client.site.getrecyclebinitems?view=sharepoint-csom\">see the documentation<\/a> for the various parameters):<\/p>\n<pre class=\"brush:javascript\">\r\nfetch(\"https:\/\/tenant.sharepoint.com\/sites\/YourSite\/_api\/site\/getrecyclebinitems?rowLimit=%2770000%27&#038;itemState=0&#038;orderby=3&#038;isAscending=false\", {\r\n  \"headers\": {\r\n    \"accept\": \"application\/json\",\r\n    \"content-type\": \"application\/json\",\r\n    \"x-requestdigest\": document.querySelector(\"#__REQUESTDIGEST\").value\r\n  },\r\n  \"method\": \"GET\",\r\n})\r\n.then(res => res.json())\r\n.then(json => {\r\n  console.log(json.value);\r\n  \/\/ it will show an array with an object that contains several interesting properties:\r\n  \/\/ AuthorEmail, AuthorName, DeletedByEmail, DeletedDate, DirName, Id, LeafName, Title, \u2026\r\n})\r\n<\/pre>\n<p>You can then filter the result to get what you need, for example if you&#8217;re looking for an item from the list \u201cProjects\u201d that has the ID 1981:<\/p>\n<pre class=\"brush:javascript\">\r\njson.value.filter(item => item.DirName.includes(\"Lists\/Projects\") &#038;& item.LeafName === \"1981_.000\");\r\n<\/pre>\n<p>Then, to restore an item, we need the <code>Id<\/code> from the previous result. The famous endpoint to restore an item is <code>_api\/site\/RecycleBin('Id')\/restore<\/code>, however it could also return the error &#8220;The attempted operation is prohibited because it exceeds the list view threshold&#8221;. In that case, we can use this other endpoint <code>_api\/site\/RecycleBin\/RestoreByIds<\/code>:<\/p>\n<pre class=\"brush:javascript\">\r\nfetch(\"https:\/\/tenant.sharepoint.com\/sites\/YourSite\/_api\/site\/RecycleBin\/RestoreByIds\", {\r\n  \"headers\": {\r\n    \"accept\": \"application\/json\",\r\n    \"content-type\": \"application\/json\",\r\n    \"x-requestdigest\": document.querySelector(\"#__REQUESTDIGEST\").value\r\n  },\r\n  \"method\": \"POST\",\r\n  \"body\":JSON.stringify({\r\n    \"ids\": [\r\n      \"4f855ee7-472b-414a-a482-4317a114c1a2\" \/\/ Id to restore\r\n    ],\r\n    \"bRenameExistingItems\": true\r\n  })\r\n})\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>It might be difficult to search for an item in a SharePoint recycle bin. I was using the end point _api\/site\/RecycleBin as a Site Collection Administrator, but in some cases it returns an error &#8220;The attempted operation is prohibited because it exceeds the list view threshold.&#8221;. The solution is to use another end point _api\/site\/getrecyclebinitems [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","hide_page_title":"","footnotes":""},"categories":[15,170,20,33],"tags":[153,123,155,158,117],"class_list":["post-2267","post","type-post","status-publish","format-standard","hentry","category-astuce","category-english","category-niveau-expert","category-programmation","tag-astuce","tag-english","tag-niveau-expert","tag-programmation","tag-sharepoint"],"_links":{"self":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/2267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/comments?post=2267"}],"version-history":[{"count":4,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/2267\/revisions"}],"predecessor-version":[{"id":2271,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/2267\/revisions\/2271"}],"wp:attachment":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/media?parent=2267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/categories?post=2267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/tags?post=2267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}