Creation of SharePoint web using Microsoft Flow
Flow team has released a new action where we can make REST api calls to the SharePoint. Going forward this action will be help full while development of applications using Microsoft flow.
I would like to show an example of how to use the REST api making action for creation SharePoint web.
Structure for making a REST API call for creation of SharePoint web is as below.
End Point: - /_api/web/webinfos/add
Type: - Post
Headers: -
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose"
}
Body: -
{'parameters':{
'__metadata':{'type':'SP.WebInfoCreationInformation'},
'Url':'test url',
'Title':'Test',
'Description':'Test Description',
'Language':'1033',
'WebTemplate':'STS#0',
'UseUniquePermissions':true
}
}
Here is the complete flow diagram.
For any flow the first step is the trigger, what will trigger the flow. For the flow I have taken the trigger is whenever a new item is added to the list.
Connector: - SharePoint
Action Name: - When an Item is created
After fetching the item that has triggered the flow, we will send an http request which will create a sub site using the item details like title.
Connector: - SharePoint
Action Name: - Send an Http Request to SharePoint
STS#0 is for team sites. If you want to find out the list of templates we can send an Http request
http://<Site Url>/_api/web/getavailablewebtemplates(lcid)
LCID= 1033
Next action is what to do if the http request returns a success, I will be using initialize a variable action to capture the returned success object data. In this scenario I am not using the data but the data will be useful if we have to update the item with sub site URL or need to send a notification for the requestor.
Connector: - Variables
Action Name: - Initialize a variable
How to configure so that the above action runs only when Http request is successful? We can set that using settings of the action like below. Select Configure run after and select success option.
For handling the error condition, we need to add a parallel condition to the Http Request action. Parallel option will help us in handling different flow of the logic.
In the parallel action add initialize a new variable for handling the error message and sending a mail.
For the above action the configure run after settings is as below. As that action needs to run whenever an error occurs for the Http request.
The final action performed is when the sub site is created successfully we will try to create security groups. Again, we will use the action Send an Http Request to SharePoint for performing this.
Anything that can be done through a Rest API call in the code now can be done using the Send an Http Request to SharePoint action.