Rename a Folder

You will need to know the following info:

  • Site Address
  • SharePoint Document List Name
  • Folder Location
  • Metadata Type (SP.Data.DocumentListNameItem)

Metadata type is the only one that is somewhat tricky to get but once you understand the format it is not too bad. Here is an example on how to get the above info needed:

The SharePoint document location I want to focus on is located here https://testsite.sharepoint.com/sales/Customers AND the folder I want to rename is United States/WA/Ellensburg

  • site address is https://testsite.sharepoint.com/sales
  • Document List Name is Customers
  • Folder location is United States/WA/Ellensburg
  • Metadata Type is SP.Data.CustomersItem
    • If your Document list name has a space then for example it would be SP.Data.Shared_x0020_DocumentsItem
    • If you list has a special character then go here to find a way to get the proper name to use above

If you like you can test a get action to see what is happening
(The below pic is from a production system and showcases using dynamic content)

If you want you can do a compose action to view the type using the following expression:

outputs('Send_an_HTTP_request_to_SharePoint_2')?['body/d/__metadata/type']

Now we move on to renaming the folder

  • Select your site address
  • Method
    • POST
  • URI:

 

_api/web/GetFolderByServerRelativeUrl('Customers/United States/WA/Ellensburg')//ListItemAllFields
  • Headers:
{
"Accept": "application/json;odata=verbose",
"X-HTTP-Method": "MERGE",
"If-Match": "*",
"Content-Type": "application/json;odata=verbose"
}
  • Body:
{ 
"__metadata": {
"type": "SP.Data.CustomersItem" 
},
"Title": "New Folder Name",
"FileLeafRef": "New Folder Name"
}

Reference:

https://sharepains.com/2020/11/03/rename-sharepoint-folder-power-automate/