Thursday, September 06, 2018

Microsoft Flow - Copy Folders with documents between Sites using REST

New day, new possible business case for Microsoft Flow... for this example how to copy folder with files between sites using Microsoft Flow Action.

Following small Business Case:

  • Provisioning of Sites and Subsites base in request (example article).
  • Sub Site needs to have Folder with Document Templates that needs to be filled by users.
  • Template folder is in root Folder and needs to be copy into Sub Site.
  • Create Flow Action base in REST to copy folder template to new Sub Site when site is created.

For this Flow i use the Send an HTTP request to SharePoint and use the following REST Service call "SP.MoveCopyUtil.CopyFolder
", this method has some time (since 2016) and is very used in JSOM and here a simple article explaining how to use it:

For this example i have a Modern Team Site where are stored the Template folder files that should be available in the provisioned Sub Sites, as shown in the image below.

After definition of Root Folder where are stored the folder/Files to be copy, you can access to Microsoft Flows and create a new Flow and add the following Flow Action "Send an HTTP request to SharePoint" there you can include the HTTP call with the following source url to destination Folder to be copied.

HTTP Method:

Site URL: {Site}

Method: POST
URI : _api/SP.MoveCopyUtil.CopyFolder
"srcUrl": "https://{tenant} Documents/Templates", "destUrl": "https://{tenant} Documents/Templates" 

The Flow definition should be enough to be executed.
You can manually execute the Flow and validate their success of the Action. 
You can use the flow history for more details, as show in the image below.

Looks like the Flow output is ok, then you access to your Sub Site Document Library and very if Folder "Templates" appears as shown in the image below.

Three articles in a week should be a record to me, looks like my small burn out is slowing disappearing...

Hope you like it,

Best Regards,
André Lage


Unknown said...

How did you find this REST call? It is undocumented which kills me.

André Lage said...

is more or less hidden,
you can use the parameters from here