Recently I was asked about creating a team template in Microsoft Teams and apply this team template to a team created using Power Automate.
As I mentioned a while ago the Education Microsoft Teams tenants are very different compared to the business tenants.
For this post I’m going to create a template team as a class team. Then i will use this template to create a new team. The template will include some channels and some documents a in the channels. All the documents will need to be copied and the channels will need to be created.
Creating a Teams team template
First steps first, I will go to Microsoft Teams and create a new class team.
In Teams I’m going to the overview of all my Teams and then I click on the Join or create team.
Now I can create my template Team
This is where I select the Class team type for my template site.
Then i supply the details of my template site.
You will notice that there is a link Create a team using an existing team as a template this is an alternative to the method described in this post if you can create teams manually. But if you want to do things in an automated way you will have to find some alternatives.
Anyway, we now have a team that is being created.
We are now ready to add some channels. I’m going to add a standard channel for Students and a private channel for teachers.
And Once I’ve created both channels, I just need to add some documents to each channel and then I’m done.
Note that the private channel might take a bit longer to be created, but after awhile the Files tab will show you an empty document library.
Now we have our template completed.
Copy a Microsoft Teams template site
So far all was easy, but now we’re going to look at the Power Automate part of the solution.
So I first go to my Power Automate site and I create a flow. I will initially use a manually starting flow but later on I would for example trigger the flow on the upload of a csv file that supplies me with the details of the teams that needs to be created.
And now you might hope that you could simply create a new team using the Create a team action. But that isn’t going to work.
When we use this action we will only find very few option. The education part is missing. I wonder if the Power Automate team forgot that there are educational tenants. So when we want to use the team template we might have to do a bit more work.
I’m going to use the Graph API. To do the Graph API I will go through the steps similar to some of my previous posts. like for example last week’s post Who is in the office tomorrow.
Creating the app registration in Azure Portal
In the app registration blade I will complete the following details:
As always I then create a secret:
And then I need to set the API Permissions:
The API permissions that I need are:
This means that in the app registration you want to add the application permissions Group.ReadWrite.All and Directory.ReradWrite.All.
Isn’t that nice. We don’t need any teams permissions to clone a team.
Building the flow to copy the team template
Then I create a Select action in the flow that has 3 mappings configured. and the SecretId, ClientId and the Tenant ID are copied from my app registration in Azure.
Then I rename the above select action to Settings and add a Parse JSON action to following the above action
The content expression in the above Parse JSON settings is set to:
Now to get an access token for the Graph API we need to add an HTTP action that will collect the access token. using the Tenant ID and the ClientID and the SecretId as configured earlier.
Then the access token can be collected from the above HTTP action using the following expression
Now that we have an access token it is time to have a look at how we can clone the template team.
Cloning a team using Power Automate
Now following the HTTP request that gets the access token I will add a get a team action. This is where i select my template team
then in another HTTP request I’m adding all the details for the team calling the following endpoint
So, the flow worked. Time to checkout my new team!
In my teams overview it looks good!
Then inside my team:
Ok, so the Student Information channel has been created. That is my public channel. The private channel is not being created.
A bit disappointing maybe as a clone should be a clone and not a poor copy, but hey, we can sort that out!
Creating a private channel
To created a private channel you have to specify an owner. So i’m first going to collect the user id for a suitable owner.
Using the Search for a user I will find a user.
And then in the following compose I collect just the first person returned by the query as I know that I will only have one person being returned this is something that will be safe.
The expression used is:
To Create a new channel we will need yet another Graph API call. The Create a Channel endpoint will require us to update the app registration permissions to include the following application permission:
Then we configure the HTTP request to create the private channel and success!
The private channel has been created matching my original team template, including the private channels