Sharepoint online http request document set recycle

Steel Contributor

I'm posting this as I couldn't find a solution online that covered my situation.

I hope the following is useful to other Digital Workplace administrators and those looking after large SharePoint instances.

 

I have 2 SharePoint Online libraries: EmployeeFiles and ExitedEmployeeFiles

They contain document sets of Employee Files. Each document set has a status. The status can be Current or Exited.

 

The use case is our HR team want to change the status of the document set, and the Power automate flow runs overnight and moves the document set as follows:

  1. document set in EmployeeFiles with Exited status , should move to ExiteEmployeeFiles library
  2. document set in ExitedEmployeeFiles with Current status, should move to EmployeeFiles library

We have a flow doing EmployeeFiles > ExitedEmployeeFiles no problem

But the new flow going the reverse direction failed and failed and failed with 502 errors.

 

The ExitedEmployeeFiles to EmployeeFiles flow has the following logic:

  • For each Status = Current document set, copy it to the EmployeeFiles library
  • If the copy was successful then send the ExitedEmployeeFiles document set to the recycle bin, just in case we need it for some reason.

The send to recycle bin action was a SharePoint http request as follows

 

 

 

 

{
    "host": {
        "connectionReferenceName": "shared_sharepointonline",
        "operationId": "HttpRequest"
    },
    "parameters": {
        "dataset": "https://companyname.sharepoint.com/sites/org-dev",
        "parameters/method": "POST",
        "parameters/uri": "_api/web/Lists/GetByTitle('Exited%20Employee%20Files')/items(28132)/recycle()",
        "parameters/headers": {
            "accept": "application/json; odata=verbose",
            "IF-MATCH": "*",
            "X-RequestDigest": "$('#__REQUESTDIGEST').val()"
        }
    }
}

 

 

 

The error code that it was giving was

 

 

 

{
  "error": {
    "code": 502,
    "source": "region-001.azure-apim.net",
    "clientRequestId": "417d03b8-e528-4f1f-b44a-a84665eba404",
    "message": "BadGateway",
    "innerError": {
      "status": 502,
      "message": "The file is currently checked out or locked for editing by another user.\r\nclientRequestId: 417d03b8-e528-4f1f-b44a-a84665eba404\r\nserviceRequestId: ddfef0a0-d098-2000-b931-5d16381a3f93",
      "source": "https://ravensdown.sharepoint.com/sites/org-dev/_api/web/Lists/GetByTitle('Exited%20Employee%20Files')/items(28132)/recycle()",
      "errors": [
        "-2130575306",
        "Microsoft.SharePoint.SPException"
      ]
    }
  }
}

 

 

 

For 2 or 3 days I tried different forms of the HTTP request to fix this issue.

But I couldn't do it.

 

The key problem I had was that the error said the item was checked out, but the item is the document set, and there is no way to check out a document set so I thought there was an issue with my HTTP request formatting.

 

>>>>> drum roll <<<<<

 

It turns out that the cause of the 502 is not the DOCUMENT set, the thing being copied and then deleted, BUT it's content files.

The document set I was doing all my testing on, happened to contain one word document checked out to a user who had left the organisation several years ago. 

 

Because the document was checked out by someone else, not the user I run my Power Automate flows with, it couldn't see the file OR take control of it.

 

Interestingly the PowerAutomateFlow could copy the document set (but not the checked out files) but to my user the same number of files existed before copying and after copying so there was no OBVIOUS reason for the error.

What the document set couldn't do was send the document set to the recycle bin.

 

Now there is a clue as to the issue, but I was too literal interpreting the error message.

"The file is currently checked out or locked for editing by another user."

Because the software team used "the file" I assumed they were talking about the document set I was trying to send to the recycle bin. BUT no the error is referring to the single file INSIDE the document set that was checked out by another user.

>>> The solution <<<

Find the checked out files and check them in.

To do this you do need special permissions.

 

Before you start you have to be an Owner of the TEAM that owns the SharePoint site, or have SharePoint site collection admin rights to the SharePoint site that the SharePoint libraries are in.

If you have this security right then you can go to the library, and click the Cog, then click "library settings" , then click "more library settings" , then click "Manage files which have no checked in version".

Then select all the documents, and click TAKE control.

Before you leave the page open all the folders, those files exist in using different tabs. Then go and check those documents in.

 

Once I'd done this, the Power Automate flow http request just worked YAH!

 

>>> For good measure <<<

Attached is a screen shot of the Power Automate HTTP request action that I used to send the file / document set / item to the recycle() bin.

I'm including it because I found it really hard to find documentation on this.

http-request-recycle-document-set-sharepoint-online.png

 

 The code for each property of the action so you can copy them is as follows

 

_api/web/Lists/GetByTitle('Exited%20Employee%20Files')/items(@{items('Apply_to_each_2')?['ID']})/recycle()

accept  application/json; odata=verbose
IF-MATCH  *
X-RequestDigest  $('#__REQUESTDIGEST').val()

 

 

 

0 Replies