Microsoft Teams templates allow creating teams with pre-defined channels, applications, and tabs. The goal of templates is to standardize team deployment across the organization and for rapidly deploying teams for specific reasons, such as project management or retail stores. Microsoft has several pre-defined templates for the healthcare, education, and retail sectors.

Just recently, Microsoft released the ability to create your own custom templates in the Teams admin center. This allows for defining your own templates to match your organization’s specific requirements.

In this post, you’ll learn how to create Microsoft Teams templates. You’ll then learn how to create a team using a template with the Graph API.

If you are new to the Graph API, you can check out my other two articles on getting started with Graph API:

Getting Started with Microsoft Teams and Graph API
Creating Microsoft Teams and Channels with Graph API and PowerShell

Create Microsoft Teams Templates

First, you’ll create a Microsoft Teams template that you will later use with the Graph API.

  1. Navigate out to the Teams admin center at https://admin.teams.microsoft.com.
  2. In the menu on the left, select Teams, then Teams templates.
  3. Displayed is a list of current templates available for help desk, patient care, or organizing a retail store.
  4. From here, go ahead and select the + Add button.

In the Create a template wizard, you have the option to create our template from scratch, from an existing team, or from an existing template. For this tutorial, create a brand new template.

Selecting microsoft teams templates starting point
Selecting the template starting point

The next page contains more information about the template, including a name, a short and long description, and the locale for the template. The template you’re building is going to be for managing projects in the IT department.

Filling out the team descriptions
Filling out the team descriptions

Next, on the next screen, set up how you want the team to be structured. You create what channels should appear in the team along with any applications for the channel. You can also configure the channel to be shown by default. For the IT Projects template, there will be 4 channels:

  • General
  • Announcements
  • Project Planning, with Planner and OneNote tabs
  • Code Talk, with the Azure DevOps tab

The app appears as a tab in the channel. The app name appears as the tab name, but you can customize this display name. You can also install apps for the entire team instead of just adding them as a tab. Add the Praise app to the team as well.

Adding channels to a template
palte

When you submit the template, the template appears in the list of templates. Select the template to view the information for the template, including the template ID, which you will need later on.

Viewing custom template information
Viewing custom template information

Creating a Team from a Template

Back in the Teams client:

  1. Navigate to the teams app on the left.
  2. Select Join or create a team, then Create a team.
  3. When creating a team, you have options to select From scratch or From a group or team. Now there is a new option for selecting a template. The new IT Projects template is available:

When creating the team, you can select whether it is Private or Public, then give the team a name and a description. The team does take a few minutes to create, and you’ll see why when you create a team using the Graph API.

Using Microsoft Teams Templates with Graph API

Now that you have a custom template to create teams, you will learn how to create teams from templates using the Graph API. The beta version of the Graph API can create teams from templates. Since these are beta, Microsoft can make changes to them at any time and are not supported in production.

First, you’ll need headers with a Graph API authorization access token using an application client ID and client secret. Review the article for more information on how to perform this:

Creating Microsoft Teams and Channels Using Graph API

First, create the request body. The request body contains details use JSON to describe the team structure. The template@odata.bind value is going to reference the template made earlier in this tutorial.

Note: The URI contains the template GUID shown after creating the template in the Teams admin center.

Next, give the team a display name, a description, and a visibility value. Since you are using application permissions to create the team, you need to specify an owner for the team.

Note: I tried using the format found here in the Microsoft Docs for specifying the owner, but this did not work for me. Instead, I used owners@odata.bind property and specified my user profile using my object ID.

Here is the full value for the $requestBody variable:

$requestBody =
'{
    "template@odata.bind": "https://graph.microsoft.com/v1.0/teamsTemplates(''909e628b-dcc5-4b92-8208-64fe15beb1ae'')",
    "displayName": "Team from Template Graph API",
    "description": "Creating a team using a template and Graph API",
    "visibility": "Public",
    "owners@odata.bind": [
      "https://graph.microsoft.com/v1.0/users/g93gh99-b1e2-4bd1-9b5a-asdfbc9999999"
    ]
}'

With the team information saved, you now make the HTTP request to the Graph API to make the team using the template. The URI will be using the beta Graph API URI https://graph.microsoft.com/beta/teams.

One thing I found out is I need to use Invoke-WebRequest instead of my usual Invoke-RestMethod. The WebRequest allows viewing the response headers whereas the RestMethod does not. I found this while researching this blog post, so if you know of a way to use RestMethod to get the response headers, please leave a comment below.

Make the request and save the results to the variable $responseData:

$responseData = Invoke-WebRequest `
    -Method POST `
    -Uri "https://graph.microsoft.com/beta/teams" `
    -Body $requestBody `
    -Headers $headers

Edit
After publishing this post, I found a way to get the response headers using Invoke-RestMethod. I wanted to post this for anyone reading later. I’ll leave the remainder of the post unchanged for reference as it is a valid way to get the information as well.

Use the -ResponseHeadersVariable parameter to save the response headers to a variable, like this:

Invoke-RestMethod `
    -Method POST `
    -Uri "https://graph.microsoft.com/beta/teams" `
    -Body $requestBody `
    -Headers $headers `
    -ResponseHeadersVariable responseHeaders

I can then view the Location value used in the next section like this:

$responseHeaders.Location

View Status of Teams Template Creation

The headers contain a Location value returned by the request. The Location value will return a partial URI:

$responseData.Headers.Location

When you create a request to create a team using a template, it is called a teamsAsyncOperation. This operation means you’ll get a response back, but the requested action may take some time to complete. This Location value is a URI endpoint you can check to see when the team has finished provisioning.

You see this same behavior in the Teams client when you created a team using a template. The Teams client displayed a message that the team will take a few minutes to get created, and this is the same async operation happening.

You can take this location value and prepend it with the Graph API value of https://graph.microsoft.com/beta to view the operation status. Use the GET method and headers with the authorizing access token:

Invoke-RestMethod `
    -Method GET `
    -Uri "https://graph.microsoft.com/beta/teams('c423d9d5-d9ec-472d-9d6e-f09be75e12c9')/operations('be7fb68d-2bef-42b6-b782-db509602fd74')" `
    -Headers $headers

Initially, the status is inProgress. To verify the team has been created successfully, continue making GET requests every 30 seconds until the status shows success (or maybe failure!).

After waiting a few minutes, the HTTP request returned a succeeded status, and the team is created.

Summary and Additional Resources

The ability to create templates to build teams from is a welcomed featured. It further extends the functionality of Microsoft Teams to allow administrators and users to customize their teams to get the most value.

One quirk I have noticed: the Teams client does not show the channels I configure to appear for all team members. When I manage the team and view the channels, they are configured to show for everyone. Perhaps this is a delay in the Teams client in showing them by default or just an issue with this being in beta.

Questions or comments? If so, drop me a note below or find me on Twitter or LinkedIn to discuss further.

Resources:
Microsoft Docs: Create team
Microsoft Docs: teamsAsyncOperation resource type
Getting Started with Microsoft Teams and Graph API
Creating Microsoft Teams and Channels with Graph API and PowerShell