Internal Server Error while adding user to MS Teams

Viewed 52

My requirement is to add a user to MS Teams via Rest API. So I am using endpoint and parameters:

https://login.microsoftonline.com/********/oauth2/v2.0/token
Body:
'@odata.type':'#microsoft.graph.aadUserConversationMember'
'roles':'[]'
'user@odata.bind':'https://graph.microsoft.com/v1.0/users('*************')

This threw me "InternalServerError". I have no idea why I am getting this error. The complete error looks like:

"code": "InternalServerError"
"message": "Failed to execute request."

Did anyone face the same scenario I am totally confused. How to get rid of it?

1 Answers

I tried to reproduce the same in my environment and I was able to add user to MS Teams like below:

I granted TeamMember.ReadWriteNonOwnerRole.All permission to the Application like below:

enter image description here

I generated access token via Postman with Client_Credential Flow by using parameters like below:

https://login.microsoftonline.com/mytenant_id/oauth2/v2.0/token
client_id=client_id
&client_secret=client_secret
&grant_type=client_credentials
&scope=https://graph.microsoft.com/.default

enter image description here

To add user to MS Teams, please use the below endpoint:

POST https://graph.microsoft.com/v1.0/teams/ID/members

'@odata.type':'#microsoft.graph.aadUserConversationMember'
'roles':'[]'
'user@odata.bind':'https://graph.microsoft.com/v1.0/users('ID')

Response:

enter image description here

Related