To add a modern team site to 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 a 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 |
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.
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.
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
{
"displayName": "['Title']",
"alias": " ['Alias']",
"isPublic": false,
"optionalParams": {
"Description": " ['Description']",
"Owners": ["[Owners_Email]"],
"CreationOptions": ["SPSiteLanguage:1033", "HubSiteId:00000000-0000-0000-0000-000000000000"]
}
}
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 “Send an Http Request” Action
Schema
{
"type": "object",
"properties": {
"d": {
"type": "object",
"properties": {
"CreateGroupEx": {
"type": "object",
"properties": {
"__metadata": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"DocumentsUrl": {},
"ErrorMessage": {},
"GroupId": {
"type": "string"
},
"SiteStatus": {
"type": "integer"
},
"SiteUrl": {
"type": "string"
}
}
}
}
}
}
}
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.
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,
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.