SOLVED
Home

Create Teams with Rest API failing.

%3CLINGO-SUB%20id%3D%22lingo-sub-481157%22%20slang%3D%22en-US%22%3ECreate%20Teams%20with%20Rest%20API%20failing.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-481157%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3C%2FP%3E%3CP%3EI'm%20following%20this%20article%20(%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fmicrosoftteams%2Fget-started-with-teams-templates%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fmicrosoftteams%2Fget-started-with-teams-templates%3C%2FA%3E)%20%26amp%3B%20this%20(%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Fapi%2Fteam-post%3Fview%3Dgraph-rest-beta%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Fapi%2Fteam-post%3Fview%3Dgraph-rest-beta%3C%2FA%3E)%20and%20calling%20the%20following%20bit%20of%20code%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EInvoke-RestMethod%20%60%3CBR%20%2F%3E-Uri%20%3CA%20href%3D%22https%3A%2F%2Fgraph.microsoft.com%2Fbeta%2Fteams%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgraph.microsoft.com%2Fbeta%2Fteams%3C%2FA%3E%20%60%3CBR%20%2F%3E-Body%20%24bodycreateteams%20%60%3CBR%20%2F%3E-ContentType%20%22application%2Fjson%22%20%60%3CBR%20%2F%3E-Headers%20%40%7BAuthorization%20%3D%20%22Bearer%20%24accesstoken%22%7D%20%60%3CBR%20%2F%3E-Method%20Post%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EI%20get%20the%20error%3A%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%3A%5CCreateTeam.ps1%20%3A%20ERROR%20occurred%3A%20The%20remote%20server%20returned%20an%20error%3A%20(400)%3CBR%20%2F%3EBad%20Request.%3CBR%20%2F%3EResponse%20body%3A%3CBR%20%2F%3EThe%20remote%20server%20returned%20an%20error%3A%20(400)%20Bad%20Request.%3CBR%20%2F%3EAt%20line%3A1%20char%3A1%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJson%20body%26nbsp%3B%20(%24bodycreateteams)%20is%3A%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%22template%40odata.bind%22%3A%20%22%3CA%20href%3D%22https%3A%2F%2Fgraph.microsoft.com%2Fbeta%2FteamsTemplates('educationClass%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgraph.microsoft.com%2Fbeta%2FteamsTemplates('educationClass%3C%2FA%3E')%22%2C%3CBR%20%2F%3E%22displayName%22%3A%20%22TeamDispName%22%2C%3CBR%20%2F%3E%22description%22%3A%20%22This%20is%20a%20EducationClass%20Template%20Teamsite%22%2C%3CBR%20%2F%3E%22visibility%22%3A%20%22Private%22%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20I%20substitue%20%22educationClass%22%20for%20retailStore%2C%20educationStaff%2C%20healthcareWard%20etc%20it%20works%20fine.%20No%20errors.%26nbsp%3BI%20have%20done%20a%20try%20catch%20around%20the%20Invoke-RestMethod%20and%20the%20message%20displayed%20is%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eerror%3CBR%20%2F%3E-----%3CBR%20%2F%3E%40%7Bcode%3DBadRequest%3B%20message%3DFailed%20to%20execute%20Templates%20backend%20request%20CreateTeamFromTemplateRequest.%20Request%20Url%3A%20%3CA%20href%3D%22https%3A%2F%2Fteams.m%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fteams.m%3C%2FA%3E...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20ideas%20anyone%3F%20I've%20also%20noticed%20that%20when%20I%20use%20the%20template%20educationProfessionalLearningCommunity%20it%20just%20creates%20a%20team%20with%20a%20standard%20template.%3C%2FP%3E%3CP%3EThanks%3CBR%20%2F%3EIswar%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-683040%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20Teams%20with%20Rest%20API%20failing.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-683040%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F323858%22%20target%3D%22_blank%22%3E%40Iswar2019%3C%2FA%3E%26nbsp%3B-%26nbsp%3BAre%20you%20creating%20this%20team%20on%20Education%20tenant%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-683061%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20Teams%20with%20Rest%20API%20failing.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-683061%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F79135%22%20target%3D%22_blank%22%3E%40Wajeed%20Hanif%20Shaik%3C%2FA%3E%26nbsp%3Bno%20I%20have%20a%20trial%20O365%20tenant.%20I%20don't%20have%20an%20education%20tenant.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIswar%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-689915%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20Teams%20with%20Rest%20API%20failing.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-689915%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F323858%22%20target%3D%22_blank%22%3E%40Iswar2019%3C%2FA%3E%20Could%20you%20please%20try%20this%20payload%20and%20check%20if%20that%20helps%3A%3C%2FP%3E%0A%3CDIV%3E%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3E%7B%3CBR%20%2F%3E%22template%40odata.bind%22%3A%20%22%3CA%20href%3D%22https%3A%2F%2Fgraph.microsoft.com%2Fbeta%2FteamsTemplates('educationClass%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgraph.microsoft.com%2Fbeta%2FteamsTemplates('educationClass%3C%2FA%3E')%22%2C%3CBR%20%2F%3E%22displayName%22%3A%20%22TeamDispName%22%2C%3CBR%20%2F%3E%22description%22%3A%20%22This%20is%20a%20EducationClass%20Template%20Teamsite%22%2C%3C%2FFONT%3E%3C%2FDIV%3E%0A%3CDIV%3E%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3E%7D%3C%2FFONT%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-690094%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20Teams%20with%20Rest%20API%20failing.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-690094%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F359599%22%20target%3D%22_blank%22%3E%40Gousia_Begum%3C%2FA%3E%26nbsp%3BThank%20you%20that%20works.%20I%20guess%20as%20its%20an%20education%20class%20template%2C%20you%20would%20not%20want%20it%20as%20a%20private%20team.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIswar%3C%2FP%3E%3C%2FLINGO-BODY%3E
Iswar2019
Occasional Contributor

Hi

I'm following this article (https://docs.microsoft.com/en-us/microsoftteams/get-started-with-teams-templates) & this (https://docs.microsoft.com/en-us/graph/api/team-post?view=graph-rest-beta) and calling the following bit of code:

 

Invoke-RestMethod `
-Uri https://graph.microsoft.com/beta/teams `
-Body $bodycreateteams `
-ContentType "application/json" `
-Headers @{Authorization = "Bearer $accesstoken"} `
-Method Post


I get the error:


:\CreateTeam.ps1 : ERROR occurred: The remote server returned an error: (400)
Bad Request.
Response body:
The remote server returned an error: (400) Bad Request.
At line:1 char:1

 

Json body  ($bodycreateteams) is:
{
"template@odata.bind": "https://graph.microsoft.com/beta/teamsTemplates('educationClass')",
"displayName": "TeamDispName",
"description": "This is a EducationClass Template Teamsite",
"visibility": "Private"
}

 

When I substitue "educationClass" for retailStore, educationStaff, healthcareWard etc it works fine. No errors. I have done a try catch around the Invoke-RestMethod and the message displayed is:

 

error
-----
@{code=BadRequest; message=Failed to execute Templates backend request CreateTeamFromTemplateRequest. Request Url: https://teams.m...

 

Any ideas anyone? I've also noticed that when I use the template educationProfessionalLearningCommunity it just creates a team with a standard template.

Thanks
Iswar

4 Replies

@Iswar2019 - Are you creating this team on Education tenant?

Hi @Wajeed Hanif Shaik no I have a trial O365 tenant. I don't have an education tenant. 

 

Iswar

Solution

@Iswar2019 Could you please try this payload and check if that helps:

{
"template@odata.bind": "https://graph.microsoft.com/beta/teamsTemplates('educationClass')",
"displayName": "TeamDispName",
"description": "This is a EducationClass Template Teamsite",
}

@Gousia_Begum Thank you that works. I guess as its an education class template, you would not want it as a private team.

 

Iswar