Forum Discussion
REST API to apply a retention Label
Is there a REST method to apply/update a retention label on a file in a library?
thanks, we are planning to release a REST API which will create the event-based retention by the end of year so stay tune (see this demo we did at Ignite: https://youtu.be/gBNcHJ7ERl8?t=2848
- I think this shgould be available throught CSOM: http://www.myfatblog.co.uk/index.php/2018/05/configuring-default-office-365-labels-using-powershell/
- Joe JamesCopper Contributor
Yes, I did see that it was available through CSOM, but I was trying to figure out what would be the REST endpoint for this. Basically, I was trying to get the field updated from a Flow.
- cfiessingerMicrosoft
Joe can you please share the end to end scenario you are trying to achieve?
- boby5555_Copper ContributorAnyway update on this? I need to create a SPFX Extensions CommandSet that will apply a retention label on the selected items in a library.
- Silje DahlCopper Contributor
If you know the name of the retention label, you should be able to do this:
Use SPHttpClient and do a POST request to to https://mytenant.sharepoint.com/sites/someSite/_api/web/Lists/GetById('someLibraryGUID')/items/documentLocalId/SetComplianceTag()
... with a body like this:{"complianceTag": "myLabel","isTagPolicyHold": "True","isTagPolicyRecord": "True"}- SukeshCrimsonCopper Contributor
Silje Dahl Can you post a working example with exact HTTP headers, I have been trying but it doesn't seem to apply.
Others: There is a mention on this thread that this will be released as a supported mechanism in Flow by MS at some point, is it released now, I tried to find but can't find it yet.
- TimHaydnJonesCopper ContributorSo, if we wrote some code to apply a retention label to files in SP using the REST API, the retention label would have been created 'automatically'. Does this mean that we would need an E5 licence? (in my opinion, the word 'automatically' is extremely ambiguous in this critical context). My initial (and I believe logical) reaction is that we would NOT need an E5 licence just because we chose to develop something using the REST API. The reason I say this, is that if we did need an E5 licence, then we'd barely need the REST API, because E5 would have brought with it the capability to automatically apply a retention label. Ergo, the very existence of the REST API suggests to me that we can use it within an E3 environment. Any views?
- Joe JamesCopper Contributor
I don't think there will be a license implication for using the REST API. Consuming the available API and implementing your own automations should not require any additional licensing..
- Rishi GuptaBrass ContributorDo we have API's which can be used to apply the retention labels for a SharePoint site or is there any alternate view to apply the retention labels programmatically on a site?
- robertoyMicrosoft
Rishi Gupta You can set the values today on the columns but we do have in the roadmap a REST API that makes labeling simpler, stay tuned for that.
- HerschelJBrass ContributorHello! I am looking for a way to GET/SET the Compliance Tag / Retention Label on a library level via API, is this possible? I would love to create a Power Automate to run on all newly created Teams/SharePoint sites and set the Retention Labels on their Documents library to adhere to our policy, ive found hundreds of examples on how to set on items, but I just want to set on the library itself. thanks!