#PowerPlatformTip 153: 'Rename a SharePoint File with Power Automate'
TL;DR: SharePoint has no rename action, one
MERGEHTTP request that updatesFileLeafRefrenames a file in place, keeping its ID, version history and metadata.
There’s no native “Rename file” action in the SharePoint connector, so people copy-and-delete files, losing the item ID, version history and metadata in the process. The clean way is a single REST call: update the item’s FileLeafRef field with a MERGE request via Send an HTTP request to SharePoint. The file keeps its ID, versions and permissions, only the name changes.
💡 Challenge
You need to rename a document in a SharePoint library from a flow, for example to enforce a naming convention or add a reference number. The standard connector only offers Copy file / Delete file, which breaks the item ID, resets version history and drops metadata. You want a true in-place rename.
✅ Solution
FileLeafRef is the internal field that holds the file name including its extension. Updating it renames the file in place. Use the Send an HTTP request to SharePoint action with a MERGE request against the list item. The item ID, versions, permissions and all other metadata stay untouched.
🔧 How It’s Done
1. Get the item’s ID and the library’s entity type.
🔸 You need the numeric list item ID (from Get files (properties), a trigger, or Get item).
🔸 Get the exact __metadata type once with a GET request:
1
_api/web/lists/getbytitle('Draft Standards')?$select=ListItemEntityTypeFullName
🔸 For a library named “Draft Standards” the value is SP.Data.Draft_x0020_StandardsItem (spaces become _x0020_).
2. Add the Send an HTTP request to SharePoint action.
🔸 Site Address: your target site.
🔸 Method: POST
🔸 Uri:
1
_api/web/lists/getbytitle('Draft Standards')/items(ID)
(replace ID with the item’s ID).
3. Set the headers for a MERGE update:
1
2
3
4
Accept: application/json;odata=verbose
Content-Type: application/json;odata=verbose
IF-MATCH: *
X-HTTP-Method: MERGE
🔸 X-HTTP-Method: MERGE turns the POST into an update; IF-MATCH: * updates regardless of the current version (eTag).
4. Set the Body, write the new name to FileLeafRef (keep the extension!):
1
2
3
4
{
"__metadata": { "type": "SP.Data.Draft_x0020_StandardsItem" },
"FileLeafRef": "Framework-Agreement-2026.pdf"
}
🔸 The type value MUST match your library’s ListItemEntityTypeFullName from step 1, it is different for every library.
The complete action: Method POST, the Uri pointing at the list item, the four Headers (Accept, Content-Type, IF-MATCH, X-HTTP-Method: MERGE) and the Body that writes the new file name into FileLeafRef.
5. Run the flow. A 204 No Content response means the rename succeeded.
🔸 Build the new name dynamically with expressions (e.g. concat('Invoice-', triggerBody()?['RefNo'], '.pdf')), just make sure the result is a valid SharePoint file name.
🧪 Variants Tested
Every call below ran against a copy of a text file in a test folder, with the file checked afterwards via _api/web/lists(guid'...')/items?$select=FileLeafRef,File_x0020_Type,FileDirRef.
No __metadata, no entity type: use odata=nometadata
🔸 With Accept: application/json;odata=nometadata and Content-Type: application/json;odata=nometadata the body shrinks to {"FileLeafRef": "ZZ tip test renamed.txt"} and the MERGE returns 204. Step 1 (looking up ListItemEntityTypeFullName) is not needed.
🔸 The same body with the odata=verbose headers fails with 400: An entry without a type name was found, but no expected type was specified. So it is either verbose headers plus __metadata, or nometadata headers without it.
No item ID either: address the file by path
🔸 _api/web/GetFileByServerRelativeUrl('/sites/PlayGround/Freigegebene Dokumente/ZZ tip test folder/ZZ tip test rename.txt')/ListItemAllFields works as the MERGE target with the same headers and body, 204. Useful when you only have the file path from a trigger.
Changing the extension does not work through FileLeafRef
🔸 MERGE with {"FileLeafRef": "ZZ tip test ext.csv"} on ZZ tip test ext.txt returned 204, but the file kept its name and File_x0020_Type stayed txt. SharePoint silently ignores an extension change on this field.
🔸 MoveTo does it: POST _api/web/GetFileByServerRelativeUrl('/sites/.../ZZ tip test ext.txt')/MoveTo(newurl='/sites/.../ZZ tip test ext.csv',flags=1) returned 200 and the file is now ZZ tip test ext.csv with file type csv.
Rename and move to another folder in one call
🔸 MoveTo(newurl='/sites/PlayGround/Freigegebene Dokumente/ZZ tip test folder/sub/ZZ tip test moved.txt',flags=1) moved the file into the sub-folder and renamed it in the same request. flags=1 overwrites an existing file with that name.
🔸 MoveTo needs no headers apart from Accept, no body and no X-HTTP-Method. A successful call answers 200 with the body {"odata.null": true}; the MERGE rename answers 204 with an empty body.
🎉 Result
The file is renamed in place. Its item ID, version history, permissions and metadata are all preserved, no copy, no delete, no broken links or lost history.
🌟 Key Advantages
🔸 True in-place rename: ID, versions and metadata survive, unlike copy-and-delete.
🔸 No premium needed: the SharePoint connector’s Send an HTTP request to SharePoint action is standard.
🔸 Fully dynamic: compute the new file name from any flow data with expressions.
🛠️ FAQ
1. Why not just use Copy file and Delete file?
That creates a new item with a new ID and wipes version history and metadata. Updating FileLeafRef renames the existing item, so everything is preserved.
2. Where do I find the correct __metadata type?
Send a GET to _api/web/lists/getbytitle('YourLibrary')?$select=ListItemEntityTypeFullName. Use that exact value, spaces in the library name are encoded as _x0020_.
3. Do I have to include the file extension in FileLeafRef?
Yes. FileLeafRef is the leaf name including the extension. Omit it and you’ll break the file type, always append .pdf, .docx, etc.
4. Can I rename a folder the same way?
Yes. Folders are also list items, so updating FileLeafRef on the folder’s item renames the folder in place.
5. Can I change the file extension with this rename?
Not through FileLeafRef: the MERGE returns 204 but the name and the File Type column stay unchanged. Use GetFileByServerRelativeUrl('...')/MoveTo(newurl='...new.csv',flags=1) instead, that renamed .txt to .csv in the test.
6. Do I still need __metadata with odata=nometadata?
No. With Accept and Content-Type set to application/json;odata=nometadata the body is just {"FileLeafRef": "new-name.pdf"}. Only the odata=verbose headers require the __metadata type.
7. How do I rename when I only know the file path, not the ID?
Send the MERGE to _api/web/GetFileByServerRelativeUrl('/sites/site/Library/folder/file.pdf')/ListItemAllFields. Same headers, same body, no ID lookup.
8. Can I move the file to another folder while renaming it?
Yes, with one MoveTo call: GetFileByServerRelativeUrl('/sites/site/Library/old.txt')/MoveTo(newurl='/sites/site/Library/sub/new.txt',flags=1). ID, versions and metadata travel with the file.
Build flows like this with confidence. The Power Automate course at the Power Platform Academy teaches you to automate your own processes in 4 weeks, live online. Prefer a quick start? The free live workshops take 30 to 45 minutes.
🔗 Related Tips
- #PowerPlatformTip 121: Filtering SharePoint File Fields with OData, how
FileLeafRef,FileRefandFileDirRefwork. - #PowerPlatformTip 58: HTTP Actions, the basics of HTTP requests in Power Automate.
- #PowerPlatformTip 47: Batch-Method within SharePoint, bulk REST operations against SharePoint.
🎥 Video Tutorial
This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy, which runs free live workshops (in German). See the next free workshop dates (in German). For companies that want this implemented for them, see KMUpower: Power Platform consulting & automation for SMEs (DACH).