Modern Team Site Creation Automation With Power Automate

To add a modern team site to the SharePoint, there are lot of approaches are there and most of them require at least some code required. But in this article, we will be using SharePoint List and Microsoft Power Automate to automate the creation process.
 
The modern Team site is not a single entity, it also creates an associated Office 365 Group, Microsoft Planner, Group Email and so on.
 
Let’s begin the automation process. And we require the below items as a pre-requisite,
  • SharePoint List
  • A Power Automate Flow

Create SharePoint list for site requests

 
The modern team site creation requires some of the metadata and based on the requires metadata. We should create a new list as Site Requests in SharePoint site with the below columns,
 
Field Name
Type
Remarks
Title
Single Line of Text
 
Alias
Single Line of Text
 
Description
Multi Lie of Text (Plain)
 
Owners
Person or Group
 
URL
URL
Hidden
GroupId
Single Line of Text
Hidden

Modern Team Site Creation Automation With Power Automate
 
After the list creation. Navigate to the Power Automate and start creating a flow.
 

Create Flow to automate the site creation

 
Click Create -> Automated Flow
 
Then from the open dialog box, enter a flow name as “Automate Site Creation” and select the “When an item is created” in SharePoint to trigger the flow. This enables the Power Automate app to trigger the flow whenever an item is created. 
 
Modern Team Site Creation Automation With Power Automate
 
After the flow is created, In the trigger option, select the site and Site Request list.
 
Then add the Send an HTTP request to SharePoint action, which is available under SharePoint category.
 
Modern Team Site Creation Automation With Power Automate
 
Then fill the fields in the action as same as below,
 

Site Address

https://sitename.sharepoint.com

Method

POST

Uri

_api/GroupSiteManager/CreateGroupEx

Headers

accept: application/json;odata.metadata=minimal

Body

  1. {  
  2.     "displayName""['Title']",  
  3.     "alias"" ['Alias']",  
  4.     "isPublic"false,  
  5.     "optionalParams": {  
  6.         "Description"" ['Description']",  
  7.         "Owners": ["[Owners_Email]"],  
  8.         "CreationOptions": ["SPSiteLanguage:1033""HubSiteId:00000000-0000-0000-0000-000000000000"]  
  9.     }  
  10. }  

 
 
Modern Team Site Creation Automation With Power Automate
 
The above action creates the Office 365 Group and SharePoint Modern team site. After the creation, we will store the newly created site url and Office 365 Group ID back to the Site Requests List. To do that first we have to parse the output json and then store the return value to the SharePoint List.
 
Add the parse JSON action from category Data Operations. Add the output of the http request action in Body field and then fill below json in the schema field.
 

Content

Body Output of “Sendan Http Request” Action

Schema

  1. {  
  2.     "type""object",  
  3.     "properties": {  
  4.         "d": {  
  5.             "type""object",  
  6.             "properties": {  
  7.                 "CreateGroupEx": {  
  8.                     "type""object",  
  9.                     "properties": {  
  10.                         "__metadata": {  
  11.                             "type""object",  
  12.                             "properties": {  
  13.                                 "type": {  
  14.                                     "type""string"  
  15.                                 }  
  16.                             }  
  17.                         },  
  18.                         "DocumentsUrl": {},  
  19.                         "ErrorMessage": {},  
  20.                         "GroupId": {  
  21.                             "type""string"  
  22.                         },  
  23.                         "SiteStatus": {  
  24.                             "type""integer"  
  25.                         },  
  26.                         "SiteUrl": {  
  27.                             "type""string"  
  28.                         }  
  29.                     }  
  30.                 }  
  31.             }  
  32.         }  
  33.     }  
  34. }  

 
Add the Update Item action from SharePoint category. Once added, select the current site, list and Id as current Item ID.
 
Then choose the URL with Site URL and GroupId with GroupId respectively from JSON output.
 
Modern Team Site Creation Automation With Power Automate
 
After updating all actions and then save the flow by clicking Save button in top right of the page. Now we will see the flow like below,
 
Modern Team Site Creation Automation With Power Automate
 
Once everything is successfully configured, and whenever you create a new item in Site Requests list which creates the new Modern Team Site Collection.
 
After the creation, the flow updates the Site URL and Office 365 group in URL and GroupID columns, respectively in the Site Requests SharePoint list.
 
What we saw so far has the steps for the simple automation, by using this as the starting point to develop the complex workflows like applying for approval from creating the site, associate with Hub site during the Site creation, applying the Site Designs after the creation and so on.