Forum Discussion
REST API to apply a retention Label
- Nov 16, 2018
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
- Silje DahlSep 23, 2019Copper 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"}- SukeshCrimsonDec 05, 2019Copper 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.
- Silje DahlDec 05, 2019Copper Contributor
SukeshCrimson here is my JSON code from an HTTP call in Logic apps. It's possible you can perform a similar call in Flow as well, but I haven't tried as there is no direct code edit there.
"Apply_Label": { "inputs": { "body": { "body": "{\n'complianceTag': '@{variables('MyComplianceTagName')}',\n'isTagPolicyHold': 'True',\n'isTagPolicyRecord': 'True'\n}", "headers": { "Accept": "application/json;odata=verbose", "Content-Type": "application/json;odata=verbose" }, "method": "POST", "uri": "_api/web/Lists/GetById('@{outputs('Library')}')/items(@{outputs('LocalDocId')})/SetComplianceTag()" }, "host": { "connection": { "name": "@parameters('$connections')['sharepointonline']['connectionId']" } }, "method": "post", "path": "/datasets/@{encodeURIComponent(encodeURIComponent(outputs('DocSite')))}/httprequest" }, "runAfter": { "XYZ": [ "Succeeded" ] }, "type": "ApiConnection" }
The following is the input interpreted by Logic Apps, including the headers and body:
{ "method": "post", "path": "/datasets/https%253A%252F%252FmyTenant.sharepoint.com%252Fsites%252FmySite/httprequest", "host": { "connection": { "name": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/MyRG/providers/Microsoft.Web/connections/sharepointonline" } }, "body": { "body": "{\n'complianceTag': 'Exact label name',\n'isTagPolicyHold': 'True',\n'isTagPolicyRecord': 'True'\n}", "headers": { "Accept": "application/json;odata=verbose", "Content-Type": "application/json;odata=verbose" }, "method": "POST", "uri": "_api/web/Lists/GetById('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')/items(1234)/SetComplianceTag()" } }