“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.
But even here I’ve seen complicated HTTP requests that I think are quite complex for most users.
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.
Method: POST
Uri: _api/web/lists/GetByTitle('<LibraryName>')/items(<DocumentID>)/validateUpdateListItem
Body:
{
"formValues":[
{
"FieldName": "FileLeafRef",
"FieldValue": "<NewFileNameWithExtension>"
}
]
}
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.
Summary
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…
You can even update the file name without creating a new version of the document with a small addition to the request. But it might get a bit more complicated if you want to update content of an existing file, not just the file name.
Hi Tom,
Thanks for your great site.
Have you ever tried to “send a HTTP request” to update a multi-choice people picker with an individual or even better an O365 group?
JSON I am trying in a POST:
{
“formValues” :
[
{
“FieldName”:”Assigned_x0020_to”,
“FieldValue”:”O365groupID”
}
],
“bNewDocumentUpdate”:false
}
Kind Regards,
Paul
Hello Paul,
Person or Group column needs a specific format for the “FieldValue”: “[{‘Key’:’claimsLogin’}]”. It works for both, users and M365 groups, e.g. to update 1 M365 group and 1 user to item.
"FieldValue": "[{'Key':'c:0o.c|federateddirectoryclaimprovider|691a0c9d-xxxx-44e8-yyyy-d6df6cd591e8'},{'Key':'i:0#.f|membership|xxx@tomriha.com'}]"
Excellent tutorial. I was struggling with thsi and your approach is simple and straightforward. The vast majority of sites use the create new file with new file name and delete old file process. This makes more sense.
This has got me so close to what I want. Thanks. Trouble isI want to use it to rename item in doc set without changing name of document set. Any ideas?
Hello Matt,
it’s been a long time since I worked with Document Sets so I’m afraid that I don’t know how to do this.
Hi Tom,
Great article, keep up the good work!
Thanks for this information. However, when I try this solution I keep getting an error that says the following:
Value cannot be null.
Parameter name: formValues
Here is the body of my request:
{
“formValues”:[
{
“FieldName”: “FileLeafRef”,
“FieldValue”: “test.pdf”
}
]
}
Do you know why this wouldn’t work?
Thank you very much
Hello again,
I got it to work. I had the wrong HTTP request type.
Excellent post. My input, after a couple of hours struggling with default Documents Library, in spanish (can’t confirm that was the issue), would be to target to the guid enpoint as:
_api/Lists(guid’81c636c1-7a88-4c47-b72d-a29cc6abc595′)/Items(#id#)/validateUpdateListItem,
already tested and worked like a charm.
To find out the guid:
* open the _api/Lists endpoint
* search an online xml viewer and search for the library name
Hello Humberto,
thank you for sharing your solution. It can be a problem if you use multiple languages on a SharePoint site and rename a list/library as it’ll rename it only for the specific language, but list guid is always unique no matter what.
I wrote about it a bit here: https://tomriha.com/use-the-correct-sharepoint-list-name-in-the-power-automate-http-request/
Thanks Tom, your solution worked so well!
Good
Hi Tom
I’ve written the flow for this, but it keeps timing out and failing. Any ideas why this would be happening?
Hello Rod,
I’d double check if the action is correctly configured, and if it is, maybe the output will tell you more on what’s going on.
Hello Tom,
I’ve tried your solution to change the file extension from .docx to .pdf. I included the file name from the Dynamic content and added ‘.pdf’ at the end. The script worked fine and didn’t gave me any errors.
However the file extension never changed to PDF.
Is there any possibility to change the file extension without loosing the ID of the document in library?
Thank you.
Hello Alex,
I think it’s possible, but maybe you need to change also the file type (File_x0020_Type) with the request? I never tried it though.