1

I have a problem with creating teams using the Microsoft Graph Api. I can get/create groups but when I try to get/create teams I get an error. I'm using postman and the group has owners and members, just as the documentation of MS, also has the permissitions it asks for groups. If somebody can help me, cause I look everywhere for a same error but no found it.

PUT https://graph.microsoft.com/v1.0/groups/{id}/team

Headers: Authorization: bearer token and content-type: json

Body is

{  
  "memberSettings": {
    "allowCreateUpdateChannels": true
  },
  "messagingSettings": {
    "allowUserEditMessages": true,
    "allowUserDeleteMessages": true
  },
  "funSettings": {
    "allowGiphy": true,
    "giphyContentRating": "strict"
  }
}

I always get the same error

{
  "error": {
    "code": "BadGateway",
    "message": "Failed to execute backend request.",
    "innerError": {
      "request-id": "45eeba8a-9d35-45e8-b42e-c60da7a47dde",
      "date": "2020-01-23T21:55:44"
    }
  }
}
DanteGz
  • 11
  • 3

1 Answers1

1

According to the Graph API docs for this, you're not calling the correct endpoint to create a new Team. It should be

POST https://graph.microsoft.com/beta/teams

and a payload similar to

Content-Type: application/json
{
  "template@odata.bind": "https://graph.microsoft.com/beta/teamsTemplates('standard')",
  "displayName": "My Sample Team",
  "description": "My Sample Team’s Description",
  "owners@odata.bind": [
    "https://graph.microsoft.com/beta/users('userId')"
  ]
}

Note that it's slightly different, as per the docs, whether you're using delegated versus application permissons.

Hilton Giesenow
  • 9,809
  • 2
  • 10
  • 24
  • When creating a Team using the Teams endpoint, the API returns no data; not even an Id for the newly created object. You also can't create a team with `members@odata.bind` like you can with a group. In order to add members to the team you then have to search groups endpoint with a filter clause (note: displayName works but this might not be unique) to obtain the Id, and then make another request to add members (untested). I've been attempting to create a group with owners and members in 1 request which returns the Id, then upgrade to a team. I get OPs error, but the team is created. – Robin Jul 07 '20 at 14:54
  • It's been a while since I last did this, but I seem to recall the docs being correct. They list the response as containing "Content-Location: /teams/{teamId}". Are you not seeing that? Note that it's a HEADER, not part of the BODY payload. – Hilton Giesenow Jul 07 '20 at 14:59
  • Ah, I'd assumed that because Invoke-RestMethod returned with zero display, and the docs say `Content-Length: 0`, that nothing was being returned. I'd not considered they'd put the Id in the header. That's... problematic :) Maybe Invoke-WebRequest has to be used. – Robin Jul 07 '20 at 15:06
  • Confirmed. Sending the create request as `$data = Invoke-WebRequest ...` means you can inspect the return response like so: `$data.headers["Location"]` and the value is something like `/teams('a1111111-11d1-41ae-11ff-d1bc011cfc1b')/operations('b1d111b1-1f1d-1cc1-1cf1-11c1f110f1f1)` – Robin Jul 07 '20 at 15:27
  • 1
    ok great, so that sounds like you got what you needed? – Hilton Giesenow Jul 07 '20 at 15:35
  • Nearly there. This helsp a lot and saves the step of having to search after creation to find the Id. I'll see about populating team members now. I'd rather be doing this via the Teams endpoints than the reverse method (group endpoint > upgrade to team) so thanks for that! – Robin Jul 07 '20 at 15:38
  • for sure, and being in a "teams" endpoint means it might cater for other things better in future too. – Hilton Giesenow Jul 07 '20 at 16:49
  • If my answer and these comments have helped, please go ahead and upvote / mark as answer, so others can see it's been useful and it might help them too. – Hilton Giesenow Jul 07 '20 at 16:50