cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
New2PA
Helper I
Helper I

Apply retention label with the action 'Send_an_HTTP_request_to_SharePoint'

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.

New2PA_0-1629966575921.png

 

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.

New2PA_1-1629966702931.png

And I built my flow as below.

New2PA_2-1629966793969.png

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?

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Expiscornovus
Super User
Super User

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
}

 

View solution in original post

Expiscornovus
Super User
Super User

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('').

View solution in original post

7 REPLIES 7
Expiscornovus
Super User
Super User

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
}

 

View solution in original post

Expiscornovus
Super User
Super User

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('').

View solution in original post

New2PA
Helper I
Helper I

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?

 

Hi @Expiscornovus 

ShubhamBajpai_0-1639654710070.png

This is the output of the flow,

ShubhamBajpai_1-1639654978733.png

The label is getting applied, but still I can delete the folder, it should not get deleted.

ShubhamBajpai_2-1639655076779.png

This is the name of label which I am trying to apply

 

Please help me on this @Expiscornovus 

Expiscornovus
Super User
Super User

Hi @ShubhamBajpai,

 

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
}

 

 

 

@Expiscornovus  you are a  genius, it worked 🙂 thanks a lot 

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Users online (2,762)