Create SharePoint Folder using POST request in MS Flows | CloudFronts

Create SharePoint Folder using POST request in MS Flows

Introduction:

This blog explains how to create folders in SharePoint when new record is created in D365 CE.

Use Case:

When new account is created in D365 CE create “Contact Documents” and “Documents” folders in SharePoint.

Pre-Requisites:

  1. D365 CE
  2. SharePoint Online
  3. Microsoft Flow

Steps to be followed:

  1. Sign in to the Microsoft flow. https://flow.microsoft.com/en-us/
  2. Go to My flows -> “+New”-> “+Automated-from blank”

3. Select “When a record is created” trigger and click on create.

4. Select “Organization Name” and “Entity Name”.

5. Click on “+New Step” and select “Compose” Action.

6.   a. Add “Account Name” from Dynamics Content in Input.

b.  Add underscore “_”

c. Click on Expression enter below formula:

toUpper(replace(triggerBody()?[‘accountid’],’-‘,”))

d. Compose should look like below:

7. Now we will create “Main folder in SharePoint” for this account.

8. Click on “+New step” and select “Send an HTTP request to SharePoint” Action.

9. Enter below details:

Site Address: Select the site address from the list.

Method: POST

Uri: _api/Web/GetFolderByServerRelativeUrl(‘account/Output of Compose‘)/Folders

Headers:

Content-Type application/json;odata=verbose
Accept application/json;odata=verbose

Body:

{ ‘__metadata’: { ‘type’: ‘SP.Folder’ }, ‘ServerRelativeUrl’:’account/ Output of Compose‘}

10. Now we will create sub folders inside the main folder.

11. Click on “+New step” and select “Send an HTTP request to SharePoint” Action.

12. Enter below details:

Site Address: Select the site address from the list.

Method: POST

Uri: _api/Web/GetFolderByServerRelativeUrl(‘account/Output of Compose/Contact Documents‘)/Folders

Headers:

Content-Type application/json;odata=verbose
Accept application/json;odata=verbose

Body:

{ ‘__metadata’: { ‘type’: ‘SP.Folder’ }, ‘ServerRelativeUrl’:’account/ Output of Compose/Contact Documents}

NOTE: “Contact Documents” is the sub folder which we want to create in main folder.

13.  Repeat “step no 12” to create “Documents” folders.

Uri: _api/Web/GetFolderByServerRelativeUrl(‘account/Output of Compose/ Documents‘)/Folders

Body:

{ ‘__metadata’: { ‘type’: ‘SP.Folder’ }, ‘ServerRelativeUrl’:’account/ Output of Compose/ Documents‘}

NOTE: “Documents” is the sub folder which we want to create in main folder.

Complete Flow:

Testing Flow

  1. Create new account record in D365 CE.
  2. Check Documents in SharePoint. 

Share Story :

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close