Rename SharePoint Folder Or File Using REST API Power Automate

We can organize our files in a SharePoint folder by using multiple files. For example, we can create different files for regions, months, years, or projects.

Sometimes, we may need to rename many files or folders when we work with them.

In this article, I will cover the following examples using the REST API validateUpdateListItem to rename SharePoint folders or files in Power Automate:

  • How to rename a single SharePoint folder
  • How to rename a single SharePoint file
  • How to rename multiple files at once by adding prefixes or suffixes

Rename REST API Endpoint

Below is a REST API endpoint that I will use in the example:

_api/web/lists/GetbyTitle('<Document Library Name>')/items(<item-ID>)/validateUpdateListItem

Where:

  • _api/web/lists: Refers to the site’s collection of lists (and libraries).
  • GetByTitle(‘<Document Library Name>’): Calls the specific list or library whose title matches the one you provided.
  • items(<item-ID>): We must pass the file or list ID.
  • validateUpdateListItem: It updates a list item or document item using field values in a special format.

Rename SharePoint Document Library Folder Using REST API

I have a document library called “Product Approval” in the example below. There is a folder called Employee Leave Management with the item ID of 4. Check the screenshot below:

power automate rename file in sharepoint using http request

Here, I want to rename the folder name to Tsinfo Leave Management using REST API:

  1. Open the Power Automate Home page and choose Instant cloud flow with trigger Manually trigger a flow.
  2. Add the Send an HTTP request to SharePoint action and provide the following parameters:
    • Site Address: Select the SharePoint Site Address from the dynamic content.
    • Method: Select POST as the method
    • Uri: Provide the below URI:
_api/web/lists/GetbyTitle('Product Approval')/items(4)/validateUpdateListItem
  1. Click on the Show all button to display all the Advanced parameters.
    • Body:
{
  "formValues": [
    {
      "FieldName": "FileLeafRef",
      "FieldValue": "Tsinfo Leave Management"
    }
  ]
}
Renaming SharePoint file using REST API with Power Automate
  1. Now save the flow and run it manually.
  2. After the flow runs successfully, go to the SharePoint Document library. You can see that your folder name has changed.
Power Automate Rename Folder in SharePoint Online Document Library using REST API

You can rename the folder using the REST API in Power Automate.

Rename SharePoint File Using REST API with Power Automate

In the same document library, I want to check the file name Employee Leave Tracking to Leave Tracking File using REST API in Power Automate.

  1. Create an Instant cloud flow with a trigger (Manually trigger a flow).
  2. Add the Send an HTTP request to SharePoint action and provide the below required parameters:
    • Site Address: Select the SharePoint Site Address where the document library is present.
    • Method: Select POST as the method
    • Uri: Provide the below URI:
_api/web/lists/GetbyTitle('Product Approval')/items(3)/validateUpdateListItem

Replace:

  1. Click on the Show all button to display all the Advanced parameters.
    • Body: Provide the below json part:
{
  "formValues": [
    {
      "FieldName": "FileLeafRef",
      "FieldValue": "Leave Tracking File"
    }
  ]
}
Rename SharePoint File Using REST API with Power Automate
  1. Now save the flow and run it manually. Next, click the Run Flow button. Once the flow runs successfully, go to the SharePoint library to check whether the file name has been renamed.
Change filename of existing file on SharePoint Document library using REST API

One interesting part is that if your file is open and you try to rename it, the name will change.

Rename Multiple Files Using REST API

Sometimes, you may have a need to add a prefix or a suffix to all the files in your Document library.

You can do this manually or one by one (using the methods shown above) if you only have a few files. But if you have many, this could take a lot of time.

In such a case, you can follow this example. I have a SharePoint document library called Certification Documents, which has 71 files. I want to add the prefix Tsinfo.

Power Automate Rename Multiple Files Using REST API

Below are the steps to rename multiple files:

  1. Use “Manually trigger a flow” (or scheduled/automated).
  2. Then add Get files (properties only) to get all files and provide the Site address and list name where the file is present.
Renaming a SharePoint Files using REST API in Power Automate
  1. Add the ‘Apply to each’ control action, and in the ‘Select an output from previous steps’ section, provide the ‘Body’ value from the ‘Get files’ dynamic content.
outputs('Get_files_(properties_only)')?['body/value']
power Automat Renaming SharePoint file using REST API
  1. Inside the Apply to each add the Send an HTTP request to SharePoint action and provide the below required parameters:
    • Site Address: Select the SharePoint Site Address where the document library is present.
    • Method: Select POST as the method
    • Uri: Provide the below URI:
_api/web/lists/GetbyTitle('Certification Documents')/items(item()?['ID'])/validateUpdateListItem
  1. Click on the Show all button to display all the Advanced parameters.
    • Body: Provide the below json part:
{
  "formValues": [
    {
      "FieldName": "FileLeafRef",
      "FieldValue": "Tsinfo item()?['{Name}']"
    }
  ]
}
Rename Folder in SharePoint Online Document Library using REST API
  1. Save the flow and run it manually. Once the flow runs successfully.
  2. Go to the SharePoint library. You can see that all the files have been renamed.
Rename SharePoint Folder or File Using the REST API with Power Automate

In the same way, you can rename the folder; you need to get the ID and provide the new name in the JSON section.

I hope you found this Power Automate REST API tutorial helpful for renaming a file or folder in a SharePoint document library.

If you want to rename the SharePoint list, check out the post “Rename SharePoint List Using Power Automate.”

You may also like the following Power Automate tutorials:

Power Apps functions free pdf

30 Power Apps Functions

This free guide walks you through the 30 most-used Power Apps functions with real business examples, exact syntax, and results you can see.

Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App