I am trying to apply a retention label to a file when it is created or modified in a SharePoint Online library if Yes/No field of this file is set to Yes.
I an following the method #9 in this article: Retention in SharePoint Online: the HOW – Joanne C Klein to invoke the Send an HTTP Request action from a Power Automate Flow to make a REST call against the document using the SetComplianceTag method.
And I built my flow as below.
Unfortunately the flow ran with a failure. The error is detected on the action 'Send_an_HTTP_request_to_SharePoint'.
Error Details:
{"odata.error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The expression \"web/lists/GetByTitle(\u2018testdoc\u2019)/items(2)/SetComplianceTag()\" is not valid."}}}
clientRequestId: e61e4c5d-f60d-43c0-9df3-867c6f549ade
serviceRequestId: 503ce99f-9012-0000-a75f-2a827b203399
OUTPUTS:
Body:
{
"status": 400,
"message": "{\"odata.error\":{\"code\":\"-1, Microsoft.SharePoint.Client.InvalidClientQueryException\",\"message\":{\"lang\":\"en-US\",\"value\":\"The expression \\\"web/lists/GetByTitle(\\u2018testdoc\\u2019)/items(2)/SetComplianceTag()\\\" is not valid.\"}}}\r\nclientRequestId: e61e4c5d-f60d-43c0-9df3-867c6f549ade\r\nserviceRequestId: 503ce99f-9012-0000-a75f-2a827b203399",
"source": "https://xxx.sharepoint.com/sites/Astralis/_api/web/lists/GetByTitle(%E2%80%98testdoc%E2%80%99)/items(2)/SetComplianceTag()",
"errors": []
}
Headers:
{
"Pragma": "no-cache",
"x-ms-request-id": "503ce99f-9012-0000-a75f-2a827b203399",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "DENY",
"Cache-Control": "no-store, no-cache",
"Set-Cookie": "ARRAffinity=10311927bc5d2db28df9fe9cefb5a0d2bc21f4f95c5f470797b6dd738bc1c4a3;Path=/;HttpOnly;Secure;Domain=sharepointonline-ea.azconn-ea.p.azurewebsites.net,ARRAffinitySameSite=10311927bc5d2db28df9fe9cefb5a0d2bc21f4f95c5f470797b6dd738bc1c4a3;Path=/;HttpOnly;SameSite=None;Secure;Domain=sharepointonline-ea.azconn-ea.p.azurewebsites.net",
"Timing-Allow-Origin": "*",
"x-ms-apihub-cached-response": "true",
"Date": "Thu, 26 Aug 2021 08:33:57 GMT",
"Content-Length": "566",
"Content-Type": "application/json",
"Expires": "-1"
}
Status Code:
400
Did i miss anything? Could my requirement be achieved by the action 'Send_an_HTTP_request_to_SharePoint'? If yes, how? If no, is there any alternative?
Solved! Go to Solution.
Hi @New2PA,
I just had a look in the interface. When I try to set it I see the POST request has an additional field I need to set, isUnlockedAsDefault. You might want to add that to your body field.
{
"complianceTag":"3YearsDeletion",
"isTagPolicyHold":false,
"isTagPolicyRecord":false,
"isEventBasedTag":false,
"isTagSuperLock":false,
"isUnlockedAsDefault":false
}
Hi @New2PA.
I just noticed the %E2%80%98, that corresponds with ‘ character in your error message 😁
Can you please use the ' character instead in the GetByTitle('').
Hi @New2PA,
I just had a look in the interface. When I try to set it I see the POST request has an additional field I need to set, isUnlockedAsDefault. You might want to add that to your body field.
{
"complianceTag":"3YearsDeletion",
"isTagPolicyHold":false,
"isTagPolicyRecord":false,
"isEventBasedTag":false,
"isTagSuperLock":false,
"isUnlockedAsDefault":false
}
Hi @New2PA.
I just noticed the %E2%80%98, that corresponds with ‘ character in your error message 😁
Can you please use the ' character instead in the GetByTitle('').
Wow!! Working like a charm😀 Much appreciated for you help. You are the king!!!
Hi @Expiscornovus ,
Once again you helped me but I am facing an issue, I am able to apply the label "00_Reference". the label gets set also but when I am deleting the files/folders it gets deleted but ideally it should not be deleted. can you help what I am missing?
This is the output of the flow,
The label is getting applied, but still I can delete the folder, it should not get deleted.
This is the name of label which I am trying to apply
Please help me on this @Expiscornovus
Hi @Anonymous,
In the previous example the retention settings of the label are different. In that example we were deleting it after 3 years (the Only delete items when they reach a certain age setting). In that setup labeled items won't be retained, but when they reach the age you choose, they will automatically be deleted from where they're stored.
In your example you want prevent it from being deleted. That type of definition comes with different retention settings. I believe in your setup the isTagPolicyHold should be true instead of false.
Try this instead:
{
"complianceTag":"00_Reference",
"isTagPolicyHold":true,
"isTagPolicyRecord":false,
"isEventBasedTag":false,
"isTagSuperLock":false,
"isUnlockedAsDefault":false
}