MS Flow - Copy File From One Library To Another Library Using REST API

In my earlier post, "MS Flow - Copy File From One Library To Other Library Using REST API", I used the default copy functionality which was provided by Microsoft Flow. 

But in this post, I am using REST API to perform the task of the copy document from one library to another library.

Steps

This is the flow of overall actions used in this process.

MS Flow - Copy File From One Library To Other Library Using REST API

I have created a flow on the file upload event.

Step 1

Initialize the variable as SiteURL,

MS Flow - Copy File From One Library To Other Library Using REST API

Step 2

Initialize the variable as source file path.

MS Flow - Copy File From One Library To Other Library Using REST API

Step 3

Initialize the variable as the destination path.

MS Flow - Copy File From One Library To Other Library Using REST API

Step 4

Add action as Send an HTTP Request to SharePoint.

MS Flow - Copy File From One Library To Other Library Using REST API

In the above action, URI needs to be replaced with the following text as,

First replace function should be changed with,

replace(concat(uriPathAndQuery(variables('SiteUrl')),variables('FilePath')),'%2b',' ')

And second Replace function should be changed with,

replace(concat(uriPathAndQuery(variables('SiteUrl')),variables('DestinationPath')),'%2b',' ')

Full Text should be visible as,

_api/web/getfilebyserverrelativeurl('@{replace(concat(uriPathAndQuery(variables('SiteUrl')),variables('FilePath')),'%2b',' ')}')/copyto(strnewurl='@{replace(concat(uriPathAndQuery(variables('SiteUrl')),variables('DestinationPath')),'%2b',' ')}',boverwrite=true)

After uploading the document in the source path, we can see that the document moves to the destination path as soon as it is uploaded.

Cheers!!