Automate Modern SharePoint Team site creation

We can learn how to automate the creation of a modern team site using the Microsoft Power Automate in simple steps.

To add a modern team site to the SharePoint, there are a lot of approaches are available 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 Flow in Power Automate

Step 1: 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 the 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.

Step 2: Create Flow to automate the site creation

Navigate to the Microsoft Power Automate service home page, there 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 the 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

[code lang=”JavaScript” gutter=”false”]
{
"displayName": "[‘Title’]",
"alias": " [‘Alias’]",
"isPublic": false,
"optionalParams": {
"Description": " [‘Description’]",
"Owners": [
"[Owners_Email]"
],
"CreationOptions": [
"SPSiteLanguage:1033",
"HubSiteId:00000000-0000-0000-0000-000000000000"
]
}
}
[/code]

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 BodyOutput of “Send an Http Request” Action
Schema

[code lang=”JavaScript” gutter=”false”]
{
"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"
}
}
}
}
}
}
}
[/code]

Add the Update Item action from the 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 the Save button in the 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 fro creating the site, associate with Hub site during the Site creation, applying the Site Designs after the creation and so on.

 

Shantha Kumar
Shantha Kumar
Articles: 280

24,849 Comments

  1. Hi,
    I get this error and not sure why. Can you help please?
    {“odata.error”:{“code”:”Request_BadRequest”,”message”:{“lang”:”en”,”value”:”Invalid value specified for property ‘mailNickname’ of resource ‘Group’.”},”requestId”:”45baa642-6820-4193-8a77-7abeee916c73″,”date”:”2022-06-01T08:33:40″,”values”:[{“item”:”PropertyName”,”value”:”mailNickname”},{“item”:”PropertyErrorCode”,”value”:”InvalidValue”}]}}

    input looks like
    {
    “displayName”: “test4”,
    “alias”: ” test4″,
    “isPublic”: false,
    “optionalParams”: {
    “Description”: “test4”,
    “Owners”: [“admin@xxxxx.co.uk”],
    “CreationOptions”: [“SPSiteLanguage:1033”,
    “HubSiteId:00000000-0000-0000-0000-000000000000”]
    }
    }

Comments are closed.