Good to know when creating a Microsoft Teams team using the Microsoft Graph

Microsoft Graph is great and I use it for all sorts of things. Among other things I use Microsoft Graph to create a new Microsoft Teams teams for an existing Office 365 Groups.

A quite simple request from PowerShell may look something like this.

$url = 'https://graph.microsoft.com/v1.0/groups/{0}/team' -f $office365GroupId

$body = '{  
        "memberSettings": {
        "allowCreateUpdateChannels": true
    },
        "messagingSettings": {
        "allowUserEditMessages": true,
        "allowUserDeleteMessages": true
    },
        "funSettings": {
        "allowGiphy": true,
        "giphyContentRating": "strict"
    }
}'

$response = Invoke-RestMethod -Uri $url -Method 'PUT' -Headers @{Authorization = "Bearer $token"} -Body $body -ContentType 'application/json' 

Read more.

You may however get some strange result if one of the current owners of the Office 365 Group is missing the proper license for Microsoft Teams. Assume that you are doing a phased roll out of Teams and some of your users have the license while others don’t.

The code sample above in PowerShell will in case above generate a 403 forbidden error message.

Invoke-RestMethod : The remote server returned an error: (403) Forbidden.
At line:19 char:13
+ $response = Invoke-RestMethod -Uri $url -Method 'PUT' -Headers @{Auth ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand 

Another option is to use the teams endpoint:

$url = "https://graph.microsoft.com/beta/teams"

$body = "{
    ""template@odata.bind"": ""https://graph.microsoft.com/beta/teamsTemplates('standard')"",
    ""group@odata.bind"": ""https://graph.microsoft.com/v1.0/groups('" + $office365GroupId + "')""
}"

$response = Invoke-RestMethod -Uri $url -Method 'POST' -Headers @{Authorization = "Bearer $token"} -Body $body -ContentType 'application/json' 

Read more.

With the teams endpoint above you will get a 500 Internal Server Error.

Invoke-RestMethod : The remote server returned an error: (500) Internal Server Error.
At line:8 char:13
+ $response = Invoke-RestMethod -Uri $url -Method 'POST' -Headers @{Aut ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

If you however do the same via the Teams client for instance, create a team for an existing Office 365 Group with owners without the Teams license you won’t get the same error messages. The team will be created without a problem.

So- make sure all you group owners have the proper licenses when using the Graph to create teams for existing Office 365 Groups.

Leave a Reply