Rename a SharePoint file via REST
Quiz question
Why do you rename via FileLeafRef instead of copying?
Solution
- A) Copying is never possible in librariesWrong. Copying works, but it creates a new item with a new ID and no version history.
- B) FileLeafRef also changes the file extensionWrong. SharePoint ignores a changed extension in FileLeafRef. For that you need MoveTo.
- C) ID, versions and metadata are keptCorrect. MERGE on FileLeafRef only changes the name. The item itself stays the same.
What it is about
The SharePoint connector has no rename action. Copying and deleting creates a new file with a new ID, without version history and metadata. A single call with "Send an HTTP request to SharePoint" is cleaner. You send a POST to the list item of the file and turn it into an update with the headers IF-MATCH: * and X-HTTP-Method: MERGE. The body contains only the FileLeafRef field with the new file name including the extension. With the odata=nometadata headers you don't need a __metadata entry. A 204 response means success. ID, versions, permissions and metadata are kept. You cannot change the file extension this way, MoveTo does that.
The expression from the tip
X-HTTP-Method: MERGEWhen to use it, when not
Use it
For naming conventions, reference numbers in the file name or corrections to uploaded files.
Better not
When the file extension or the folder should change. MoveTo is the right call for that.
Most common mistake
Writing the name without the extension into FileLeafRef. The file name always includes the extension.
License
Standard Runs without a premium connector, so the license from Microsoft 365 is enough. Source on Microsoft Learn: SharePoint, Connector-Referenz. For your whole flow: License check.
Prefer to learn with guidance? The Power Automate live course of the Power Platform Academy takes you from the basics to error handling and scopes in four weeks.
Share
Short link: powerautomate.ninja/en/153
Source: PowerPlatformTip #153, Microsoft Learn: Working with the SharePoint Send HTTP Request flow action.