How to Rename a SharePoint Folder or File using REST API with Power Automate

Short notes on how rename a SharePoint folder or file using the SharePoint REST API

1. Rename a Folder

In the example below the folder “Another Demo Library”, which has the item ID of 72, will be renamed. The flow will rename this folder (item ID 72) to “Renamed Folder”:

This is the HTTP request to rename a folder

Here is the folder being renamed to “Renamed Folder”

Here is the code for the API request using the POST action:

_api/web/lists/GetbyTitle('Another Demo Library')/items(72)/validateUpdateListItem

{
  "formValues": [
    {
      "FieldName": "FileLeafRef",
      "FieldValue": "Renamed Folder"
    }
  ]
} 

2. Rename a File

Here is a method to rename a file.

Flow to check-out the file, rename the file and then check-in the file.
Click above to see larger image

We can use the SharePoint item ID to check-out the file, rename the file and then check-in the file.

We can use the SharePoint item ID to check-out the file, rename the file and then check-in the file.
Flow to rename a file using the check out/ check in actions:
_api/web/lists/GetbyTitle('Documents')/items(8)/validateUpdateListItem

Body:
{
  "formValues": [
    {
      "FieldName": "FileLeafRef",
      "FieldValue": "TEST123ABC.docx"
    }
  ]
}

Example

When a file is created (properties only) trigger.
Power Automate When a file is created trigger
Get file content using path
Power automate Get file content using path

In this step I want to save the file to OneDrive before it gets renamed:

Create file in OneDrive for Business
Power automate OneDrive for Business Create file action
Check out file
Power automate check out file
Use a HTTP request to SharePoint to rename file
Power automate Send an HTTP request to SharePoint
Check in file
Power automate check in file

Sample runtime output:

Sample runtime output of the flow
Power automate sample runtime output

For Further reading

For various other ways to rename a file using Power Automate, see the following post: Power Automate Rename File


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Website Built with WordPress.com.

Up ↑

%d bloggers like this: