Simple HTTP request to rename a file in SharePoint with Power Automate
Posted On April 7, 2021
“Why can’t Power Automate rename a file in SharePoint in the same way it can rename a file in OneDrive? It’s one of the most basic operations!”
Power Automate is still missing an action that will allow you to rename a file in SharePoint. You can update all the file properties with the ‘Update file properties’ action, but file name is not one of them.
One solution I’ve seen is to ‘Copy file’ with a new name, and then delete the original one. It’ll achieve the goal, but it’ll create a new file with new ID, new link, and empty version history. I don’t think it’s a good solution.
Another, much better solution is to update the file name with an HTTP request. As already mentioned a few times on this blog, HTTP requests give you much more control. The limitations of the standard Power Automate actions don’t apply to HTTP requests, the only limitation for them is what the SharePoint REST API allows you to do. And it allows you to update the file name.
The HTTP request doesn’t have to be as complicated, you don’t need a SharePoint consultant to create it for you.
Simple HTTP request
You can use the same HTTP request as when updating a single SharePoint column. If you define the update operation in the ‘Uri’, you don’t need all the headers. And if you use the right operation, you don’t even need such complicated ‘Body’. The request below is all you need to rename a file.
Why is the “FieldName”: “FileLeafRef” and not “Name”? As already explain in the article on searching files by their name, FileLeafRef represents the file name. It’s an internal column name that’s used in SharePoint for ages, even though it’s not visible anywhere in the properties. Just don’t forget to include also the file extension in the file name.
Changing file name is a basic operation for every document storage, and it’s strange that Power Automate doesn’t have an action to rename files stored in SharePoint. But as already shown multiple times, there’s a workaround. And the workaround doesn’t have to be complicated, it can be a simple HTTP request. Simple, if you know the ‘Uri’, ‘Body’ and the internal name for the ‘Name’ property…