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.
I have created a flow on the file upload event.
Step 1
Initialize the variable as SiteURL,
Step 2
Initialize the variable as source file path.
Step 3
Initialize the variable as the destination path.
Step 4
Add action as Send an HTTP Request to SharePoint.
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!!