Flow Tips: Create Folder In SharePoint Library Using Microsoft Flow

In this post, I am going to explain how to create a new folder under root directory (or sub folder) in a SharePoint document library using Microsoft Flow. You may have this requirement in automatic trigger from some other activity in Office 365 resource, here I have explained with manual trigger, but you can use the same action in your automatic flow trigger by just passing the required parameters.

Required Flow Action

We can use the Send an HTTP request to SharePoint action to create a folder in SharePoint List.

Required Input Parameters

  • Site Address
  • Relative Folder Path 
  • New Folder Name

Create Folder under Root Folder of the Document Library

In my case I am trying to add folder in default document library (Documents) and its root folder name is “Shared Documents”.

1. Go to Microsoft Flow page.
2. Select My flows -> click New -> Instant – from blank.
3. Name your flow as “Create Folder” -> choose the trigger option From Microsoft Flow -> click Create.
4. Click Next step -> select SharePoint -> choose the action Send an HTTP request to SharePoint
5. In action parameter box, enter Site Address, select request method as POST, set Uri with your relative root folder path, set relative new folder path in request Body and set Headers.

Site Address : https://YourTenant.sharepoint.com/sites/TestSite
Method : POST

Uri :

_api/web/GetFolderByServerRelativePath(decodedurl='Shared Documents')/Folders

Headers :

accept : application/json;odata=verbose
content-type : application/json;odata=verbose

Body:

{ '__metadata': { 'type': 'SP.Folder' }, 'ServerRelativeUrl': 'Shared Documents/New Folder'}
Create List In SharePoint Library Using Microsoft Flow

Create Folder under Sub Folder of the Document Library

You just need to provide the relative path of your sub folder in Uri and request Body, other parameters are same.

Uri :

_api/web/GetFolderByServerRelativePath(decodedurl='Shared Documents/Sub Folder')/Folders

Body:

{ '__metadata':{ 'type':'SP.Folder' },'ServerRelativeUrl':'Shared Documents/Sub Folder/New Folder'}
Create Sub Folder In Document Library Using Microsoft Flow



Note: Ensure that your Sub Folder was already created, in my testing the flow runs continuously if the sub folder not available in the specified location.

Here I am using default document library (Documents), and its root folder name is “Shared Documents”. If you try to create folder in another library (ex: DocumentLib1), then by default your root folder name is same as the library name. In this case you have to provide following parameters.

Uri :

_api/web/GetFolderByServerRelativePath(decodedurl='DocumentLib1')/Folders

Body:

{ '__metadata':{ 'type':'SP.Folder' },'ServerRelativeUrl': 'DocumentLib1/New Folder'}

Advertisement

Leave a Comment