SOLVED

REST API to apply a retention Label

Copper Contributor

Is there a REST method to apply/update a retention label on a file in a library?

22 Replies

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.

Joe can you please share the end to end scenario you are trying to achieve?

@Christophe Fiessinger I have site with retention Labels published on it. The document library in question uses these labels. There is a default label set as well. Based on the type/content of document users upload they change the label value to a more relevant one.

I was trying to automate some aspects of it by creating a Flow that will apply a specific Label based on lets say value of a column. Flow can call SharePoint Rest APIs easily, and hence the question.

Did not want to pass the call onto an Azure Function or something, but I know that is an option.

Did you ever find out if there is a REST API that could be used for this?

Not yet. Could not spend too much time on it yet. But still keen to find it out.

best response confirmed by Joe James (Copper Contributor)
Solution

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

Any update on this?

Yes we've made the following announcements on January 29th: Simplify processes and meet your requirements with new records management updates which includes document REST API for event based retention: https://docs.microsoft.com/en-us/office365/securitycompliance/automate-event-driven-retention 

Great stuff, Thank you!
Anyway update on this? I need to create a SPFX Extensions CommandSet that will apply a retention label on the selected items in a library.

@boby5555_ 

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/docum...()


... with a body like this:
{
"complianceTag": "myLabel",
"isTagPolicyHold": "True",
"isTagPolicyRecord": "True"
}

@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. 

@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()"
    }
}

 

 

can we also apply sensitivity labels on team site/folders using above api ?

So, 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?

@TimHaydnJones 

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..

Do 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?

@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.

1 best response

Accepted Solutions
best response confirmed by Joe James (Copper Contributor)
Solution

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

View solution in original post