Forum Discussion

pallavi_r's avatar
pallavi_r
Super User
1 year ago
Solved

Sharepoint Recycle Bin as Datasource

Hi All,

 

Can I access the details of sharepoint site - > recycle bin content/list from Power BI.

 

The recycle bin list shows file name and how many days the file will be deleted. I have to capture this in the report.

 

Kindly advise.

 

Thanks,

Pallavi

  • Hi pallavi_r 

    I'm not sure if this meets your requirements, but I was able to query the list of files (but not content of files) in a SharePoint Online site's recycle bin with this:

     

     

    let
        SiteURL = "https://YOUR_TENANT.sharepoint.com/sites/YOUR_SITE",
        SharePointRecycleBin = OData.Feed(SiteURL & "/_api/web/RecycleBin")
    in
        SharePointRecycleBin

     

     

    Appears to refresh successfully in the service with OAuth credentials.

  • OwenAuger's avatar
    OwenAuger
    1 year ago

    Hi pallavi_r 

    Glad that this helped!

    I did some testing at my end to locate files in the Second-Stage Recycle Bin (aka Site Collection Recycle Bin).

     

    For my test site, it appears that if you use the above query with path

     

    "/_api/site/RecycleBin"

     

     and filter on ItemState = 2, this corresponds to the Second-Stage Recycle Bin.

     

    So the full query to get Second-Stage Recycle Bin that worked in my case is:

     

    let
        SiteURL = "https://YOUR_TENANT.sharepoint.com/sites/YOUR_SITE",
        SharePointRecycleBin = OData.Feed(SiteURL & "/_api/site/RecycleBin"),
        #"ItemState 2" = Table.SelectRows(SharePointRecycleBin, each ([ItemState] = 2))
    in
        #"ItemState 2"

     

    This worked for me at least. I think technically the Second-Stage Recycle Bin exists per site collection rather than per site (in my case there is one site per collection anyway), so the query may vary when multiple sites are in one collection, but I'm not an expert on this aspect of SharePoint Online myself 😉

     

    Does something like this work for you?

10 Replies

  • Hi pallavi_r 

    I'm not sure if this meets your requirements, but I was able to query the list of files (but not content of files) in a SharePoint Online site's recycle bin with this:

     

     

    let
        SiteURL = "https://YOUR_TENANT.sharepoint.com/sites/YOUR_SITE",
        SharePointRecycleBin = OData.Feed(SiteURL & "/_api/web/RecycleBin")
    in
        SharePointRecycleBin

     

     

    Appears to refresh successfully in the service with OAuth credentials.

    • pallavi_r's avatar
      pallavi_r
      Super User

      Hi OwenAuger ,

      Thanks for you reply. I was trying the steps mentioned above, but I am not getting anything. This is giving some xml which does not have list. Could you please put the step by step snapshot for my reference.

      That will be great help.

      Thanks,

      Pallavi

    • pallavi_r's avatar
      pallavi_r
      Super User

      Hi OwenAuger ,

      Thanks for you reply. I was trying the steps mentioned above, but I am not getting anything. This is giving some xml which does not have list. Could you please put the step by step snapshot for my reference.

      That will be great help.

      Thanks,

      Pallavi

    • pallavi_r's avatar
      pallavi_r
      Super User

      Hi OwenAuger ,

      Thanks a lot. It worked finally. I just modified your code from web to site. its working.

      let
          SiteURL = "https://YOUR_TENANT.sharepoint.com/sites/YOUR_SITE",
          SharePointRecycleBin = OData.Feed(SiteURL & "/_api/site/RecycleBin")
      in
          SharePointRecycleBin

       

      Thank you so much. Appreciate a lot. 

      Any idea we can get to second stage recycle bin?

       

      Thanks,

      Pallavi

      • OwenAuger's avatar
        OwenAuger
        Super User

        Hi pallavi_r 

        Glad that this helped!

        I did some testing at my end to locate files in the Second-Stage Recycle Bin (aka Site Collection Recycle Bin).

         

        For my test site, it appears that if you use the above query with path

         

        "/_api/site/RecycleBin"

         

         and filter on ItemState = 2, this corresponds to the Second-Stage Recycle Bin.

         

        So the full query to get Second-Stage Recycle Bin that worked in my case is:

         

        let
            SiteURL = "https://YOUR_TENANT.sharepoint.com/sites/YOUR_SITE",
            SharePointRecycleBin = OData.Feed(SiteURL & "/_api/site/RecycleBin"),
            #"ItemState 2" = Table.SelectRows(SharePointRecycleBin, each ([ItemState] = 2))
        in
            #"ItemState 2"

         

        This worked for me at least. I think technically the Second-Stage Recycle Bin exists per site collection rather than per site (in my case there is one site per collection anyway), so the query may vary when multiple sites are in one collection, but I'm not an expert on this aspect of SharePoint Online myself 😉

         

        Does something like this work for you?