Get retention policy labels from files or libraries on SharePoint online

xp 1 Reputation point
2021-02-03T19:00:28.83+00:00

I'm trying to find a way to get Retention policy details applied to specific files or libraries on SharePoint Online. Can we get that information using CSOM API or Graph API or any other APIs

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Baker Kong-MSFT 3,801 Reputation points
    2021-02-04T08:24:53.507+00:00

    Hi @xp ,

    I apply a label on a file and I could get it through below endpoint:

    63962-image.png

    63880-image.png

    More references:

    Best Regards,
    Baker Kong


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  2. Alcala, Jesus 6 Reputation points
    2022-07-04T14:19:02.68+00:00

    The other way is using PowerShell

    This way I make a report with the retention labels in a Library

    NOTE: Requiere to install PnP.PowerShell
    cmdlet: Install-Module -Name PnP.PowerShell

    # To Create Report file localy  
    $CSVFile = "C:\ReportLocation\ListItem.csv"  
      
        $SiteURL = "https://companysite.sharepoint.com/sites/SiteNaame"  
        $xmlQuery =  "<View Scope='RecursiveAll'><RowLimit>5000</RowLimit></View>"  
          
        Connect-PnPOnline -Url $SiteURL -UseWebLogin  
        $Lists= Get-PnPList | Where {$_.BaseTemplate -eq 101 -and $_.Hidden -eq $false}  
          
           foreach ($List in $Lists){   
              $ListItems = Get-PnPListItem -List $List.Title -PageSize 5000 -Query $xmlQuery  
                   ForEach($Item in $ListItems) {   
                      #Collect Documents Data  
                       $Data = new-object PSObject  
                       $Data | Add-member NoteProperty -Name "ID" -Value $List.Id  
                       $Data | Add-member NoteProperty -Name "List Title" -Value $List.Title  
                       $Data | Add-member NoteProperty -Name "File URL" -Value $Item.fieldvalues.FileRef  
                       $Data | Add-member NoteProperty -Name "File Name" -Value $Item.FieldValues.FileLeafRef  
                       $Data | Add-member NoteProperty -Name "Type" -Value $Item.FieldValues.FSObjType  
                       $Data | Add-member NoteProperty -Name "Label" -Value $Item.FieldValues._ComplianceTag  
                        $ListInventory += $Data  
                  }  
         }  
      
    # Save Report locally  
    $ListInventory | Export-CSV $CSVFile -NoTypeInformation  
    
     
          
    
    1 person found this answer helpful.
    0 comments No comments

  3. sadomovalex 3,636 Reputation points
    2021-02-08T15:54:44.247+00:00

    such endpoint may not be available publicly: we faced with similar issue when needed to get list of sensitivity labels settings (like does each label allows external users or should group be public or private). There is no public API for that currently.

    However what you can try is to analyze network traffic with Fiddler or browser network tab on the form where you see list of all retention labels. It may be so that you will find some non-public API calls which return what you need.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.