create group / team is failing with error 400 bad request

%3CLINGO-SUB%20id%3D%22lingo-sub-2270022%22%20slang%3D%22en-US%22%3Ecreate%20group%20%2F%20team%20is%20failing%20with%20error%20400%20bad%20request%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2270022%22%20slang%3D%22en-US%22%3E%3CP%3Ehey%20Guys%2C%3C%2FP%3E%3CP%3EI%20hope%20someone%20can%20push%20me%20into%20the%20right%20direction.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20having%20trouble%20to%20create%20a%20MS%20teams%20team%20via%20the%20graph%20API.%20I%20constantly%20get%20error%20400%20Bad%20request.%3C%2FP%3E%3CP%3Ethe%20wired%20thing%20is%20that%20I%20only%20have%20this%20problem%20in%20one%20tenant%20my%20other%20tenants%20are%20working%20with%20the%20same%20code%20example%20without%20any%20problem.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20an%20sidenote%20I%20switched%20of%20group%20creation%20for%20everyone.%20I%20used%20this%20script%20to%20do%20so%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fmicrosoft-365%2Fsolutions%2Fmanage-creation-of-groups%3Fview%3Do365-worldwide%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fmicrosoft-365%2Fsolutions%2Fmanage-creation-of-groups%3Fview%3Do365-worldwide%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20for%20my%20understanding%20this%20should%20not%20interfear%20with%20my%20application.%20But%20only%20to%20be%20100%25%20sure%20I%20added%20my%20application%20to%20the%20security%20group%20which%20is%20allowed%20to%20create%20unified%20groups%20...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20I%20still%20have%20this%20Bad%20request%20Error...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20code%20is%20looking%20like%20this%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3Efunction%20get-access%20()%0A%7B%0A%20%20%24connectionDetails%20%3D%20%40%7B%0A%20%20%20%20'TenantId'%20%20%20%20%20%20%20%20%3D%20'domain.tld'%0A%20%20%20%20'ClientId'%20%20%20%20%20%20%20%20%3D%20'xxxxxxxx-xxx-xxxx-xxxx-xxxxxxxxxxxx'%0A%20%20%20%20'ClientCertificate'%20%3D%20Get-Item%20-Path%20'Cert%3A%5CCurrentUser%5CMy%5C9DA37xxxxxxxx'%0A%20%20%7D%0A%0A%0A%0A%20%20%24token%20%3D%20Get-MsalToken%20%40connectionDetails%0A%0A%20%20%24authHeader%20%3D%20%40%7B%0A%20%20%20%20'Authorization'%20%3D%20%24token.CreateAuthorizationHeader()%0A%20%20%7D%0A%20%20return%20%24authHeader%0A%7D%0A%0Afunction%20get-id%20(%24upn)%0A%7B%0A%20%20%24URL%20%3D%20%22https%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fusers%2F%24upn%22%0A%20%20%24ResultOwner%20%3D%20Invoke-RestMethod%20-Headers%20%24headers%20-Uri%20%24URL%20-Method%20Get%0A%20%20return%20%24ResultOwner.id%0A%7D%0A%0Afunction%20create-team%20(%24owner_upn%2C%20%24team_displayname%20%2C%24team_description)%0A%7B%0A%20%20%24ownerid%20%3D%20get-id%20%24owner_upn%0A%0A%20%20%24requestBody%20%3D%20%40%22%0A%7B%0A%20%20%20%20%22template%40odata.bind%22%3A%20%22https%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2FteamsTemplates('standard')%22%2C%0A%20%20%20%20%22displayName%22%3A%20%22%24team_displayname%22%2C%0A%20%20%20%20%22description%22%3A%20%22%24team_description%22%2C%0A%20%20%20%20%22visibility%22%3A%20%22Private%22%2C%0A%20%20%20%20%22owners%40odata.bind%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22https%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fusers%2F%24ownerid%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%7D%0A%22%40%0A%20%20%24requestBody%0A%0A%20%20%24result%20%3D%20Invoke-WebRequest%20-Method%20POST%20-Uri%20'https%3A%2F%2Fgraph.microsoft.com%2Fbeta%2Fteams'%20-Body%20%24requestBody%20-Headers%20%24headers%0A%0A%0A%0A%20%20return%20%24result.headers.Location%0A%7D%0A%0A%24headers%20%3D%20get-access%0A%24result%20%3D%20create-team%20-owner%20upn_user%40domain.tld%20-team_displayname%20%22test-team0815%22%20-team_description%20%22test%20team%20description%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20as%20mentioned%20this%26nbsp%3B%20example%20is%20working%20in%20one%20tenant%20and%20not%20in%20my%20other%20tenant%20...%20And%20i%20have%20no%20idea%20why%20this%20is%20the%20case%20....%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20helping%20me%20out%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHave%20a%20nice%20day%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EChristoph%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2275784%22%20slang%3D%22en-US%22%3ERe%3A%20create%20group%20%2F%20team%20is%20failing%20with%20error%20400%20bad%20request%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2275784%22%20slang%3D%22en-US%22%3EHi%20Christoph%2C%3CBR%20%2F%3E%3CBR%20%2F%3EInterestingly%20I%20am%20also%20experiencing%20this%20issue%20within%20our%20M365%20tenant.%20This%20has%20only%20been%20a%20problem%20for%20the%20last%20few%20days%20aswell%2C%20which%20would%20indicate%20an%20issue%20being%20present.%3CBR%20%2F%3E%3CBR%20%2F%3EWould%20be%20interested%20to%20hear%20what%20Microsoft%20have%20to%20say%20about%20this.%3CBR%20%2F%3E%3CBR%20%2F%3EKind%20regards%2C%3CBR%20%2F%3E%3CBR%20%2F%3ESam%3C%2FLINGO-BODY%3E
New Contributor

hey Guys,

I hope someone can push me into the right direction.

 

I having trouble to create a MS teams team via the graph API. I constantly get error 400 Bad request.

the wired thing is that I only have this problem in one tenant my other tenants are working with the same code example without any problem.

 

As an sidenote I switched of group creation for everyone. I used this script to do so

 

https://docs.microsoft.com/en-us/microsoft-365/solutions/manage-creation-of-groups?view=o365-worldwi...

 

As for my understanding this should not interfear with my application. But only to be 100% sure I added my application to the security group which is allowed to create unified groups ...

 

But I still have this Bad request Error...

 

My code is looking like this

function get-access ()
{
  $connectionDetails = @{
    'TenantId'        = 'domain.tld'
    'ClientId'        = 'xxxxxxxx-xxx-xxxx-xxxx-xxxxxxxxxxxx'
    'ClientCertificate' = Get-Item -Path 'Cert:\CurrentUser\My\9DA37xxxxxxxx'
  }



  $token = Get-MsalToken @connectionDetails

  $authHeader = @{
    'Authorization' = $token.CreateAuthorizationHeader()
  }
  return $authHeader
}

function get-id ($upn)
{
  $URL = "https://graph.microsoft.com/v1.0/users/$upn"
  $ResultOwner = Invoke-RestMethod -Headers $headers -Uri $URL -Method Get
  return $ResultOwner.id
}

function create-team ($owner_upn, $team_displayname ,$team_description)
{
  $ownerid = get-id $owner_upn

  $requestBody = @"
{
    "template@odata.bind": "https://graph.microsoft.com/v1.0/teamsTemplates('standard')",
    "displayName": "$team_displayname",
    "description": "$team_description",
    "visibility": "Private",
    "owners@odata.bind": [
                            "https://graph.microsoft.com/v1.0/users/$ownerid"
                           ]
}
"@
  $requestBody

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



  return $result.headers.Location
}

$headers = get-access
$result = create-team -owner upn_user@domain.tld -team_displayname "test-team0815" -team_description "test team description"

 

And as mentioned this  example is working in one tenant and not in my other tenant ... And i have no idea why this is the case ....

 

Thanks for helping me out 

 

Have a nice day

 

Christoph

 

2 Replies
Hi Christoph,

Interestingly I am also experiencing this issue within our M365 tenant. This has only been a problem for the last few days aswell, which would indicate an issue being present.

Would be interested to hear what Microsoft have to say about this.

Kind regards,

Sam

@taylosa 

 

hey Sam,
its working now! I think there was a problem in the backend. I got the advice to look deeper into that error response which is not so easy in PowerShell.

 

So used postman to see if I could get more information.
If I used my custom template, I got the following error

 

A template with id 'myTemplateID' and locale 'en-US' could not be found

 

Even if I changed the ID to standard I got an error ... very odd.

 

And this behavior is gone since  yesterday ..  So for me its working as expected .

 

I am not sure if you are using Powershell for your post but I do and I  forgot to put -ContentType "application/json" into my invoke-webrequest 

 

Also not sure why this was needed for one tenant but not for the other... make no sence 

 

$requestBody = @"
{
    "template@odata.bind": "https://graph.microsoft.com/v1.0/teamsTemplates('f78f97a1-7e03-47db-90e9-421859bc7d71')",
    "displayName": "$team_displayname",
    "description": "$team_description",
    "visibility": "Public",
    "owners@odata.bind": [
                            "https://graph.microsoft.com/v1.0/users/<ownerID>"
                           ]
}
"@


$result = Invoke-WebRequest -Method POST -Uri "https://graph.microsoft.com/beta/teams" -Body $requestBody -Headers $headers -ContentType "application/json"

 

So my advice give it a shot on your end  again :)

 

Have a nice weekend

 

Christoph