PortiBlog

Power Automate to Copy and Move Document sets using REST

7 juli 2020

Within the same project as my last blog on Power Automate & OData Queries we had to copy some content. Besides sending notifications in some cases, we had to copy a Document Set to a separate library. This copy action had to capture the status of the Document Set. This of course had to happen using the correct metadata and all files within the Document Set.

Copy a Document Set

Copy a Document Set
There is no action available in Power Automate to do this by default. There is the Copy File or Copy Folder, but the copy folder did not supply the solution we were looking for. In most scenarios the Copy Folder should work as pointed out at the PowerUsers forum. In our case we chose not to spend too much time on figuring out what limitation we hit. We just worked around it using the SharePoint REST action. Using the SharePoint REST action, you can use the REST CreateCopyJobs. A nice write up on how to use the API can be found on The CreateCopyJobs API, copy or move SharePoint files or folders. So the copy action is straight forward:

  • A post to the correct API
  • A body with some settings
    • The folder that we want to copy
    • The library to copy to
    • The settings we want to copy with

Once you have decided on those settings, all you need is the SharePoint REST action. Set the site address to the correct site collection. Then set the method to POST and the URI to /_api/site/CreateCopyJobs and set the body:

{
"exportObjectUris":[
"@{variables('siteUrl')}/Lists/Library1/@{items('Iteration')?['{Name}']}"
],
"destinationUri":"@{variables('siteUrl')}/Lists/Library1",
"options":{
"IgnoreVersionHistory":true,
"IsMoveMode":false
}
}

Making the full action look as follows:

20200629-PortiBlog-Power-Automate-Rest-image01

Executing the POST request will return a 200 status if all is correct. If required, you can use the /_api/site/GetCopyJobProgress to check the status. You can even poll the status until it has the JobStatus 0 so you know the copy was successful before proceeding to the next action.

Originally posted at: https://www.cloudappie.nl/powerautomate-copydocset-rest/ 

 

Submit a comment