Share via

Unable to create team using Microsoft Graph

Anonymous
2022-07-22T05:43:16.43+00:00

I couldn't create a team using Microsoft Graph.
I created the same code as the sample.
https://learn.microsoft.com/ja-jp/graph/api/team-post?view=graph-rest-1.0&tabs=csharp

Code I created:

var team = new Team  
            {  
                DisplayName = "My Sample Team",  
                Description = "My Sample Team’s Description",  
                AdditionalData = new Dictionary<string, object>()  
    {  
                {"******@odata.bind", "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"}  
    }  
            };  
  
            await graphClient.Teams  
                .Request()  
                .AddAsync(team);  

I get an error when I run the program. What is the cause?

Error Message:
-------
Microsoft.Graph.ServiceException: 'Code: BadRequest
Message: Failed to execute Templates backend request CreateTeamFromTemplateRequest. Request Url: https://teams.microsoft.com/fabric/apac/templates/api/team, Request Method: POST, Response Status Code: BadRequest, Response Headers: Strict-Transport-Security: max-age=2592000
x-operationid: 39f128277056db4890848f3237a8a9e2
x-telemetryid: 00-39f128277056db4890848f3237a8a9e2-8de8f17b72c4ea40-00
X-MSEdge-Ref: Ref A: 91E0B0F1E6884B9EA0343B362FDCF1D8 Ref B: TYAEDGE0712 Ref C: 2022-07-22T05:13:12Z
Date: Fri, 22 Jul 2022 05:13:11 GMT
, ErrorMessage : {"errors":[{"message":"A team owner must be provided when creating a team in application context.","errorCode":"Unknown"}],"operationId":"39f128277056db4890848f3237a8a9e2"}
Inner error:
Code: BadRequest
Message: Failed to execute Templates backend request CreateTeamFromTemplateRequest. Request Url: https://teams.microsoft.com/fabric/apac/templates/api/team, Request Method: POST, Response Status Code: BadRequest, Response Headers: Strict-Transport-Security: max-age=2592000
x-operationid: 39f128277056db4890848f3237a8a9e2
x-telemetryid: 00-39f128277056db4890848f3237a8a9e2-8de8f17b72c4ea40-00
X-MSEdge-Ref: Ref A: 91E0B0F1E6884B9EA0343B362FDCF1D8 Ref B: TYAEDGE0712 Ref C: 2022-07-22T05:13:12Z
Date: Fri, 22 Jul 2022 05:13:11 GMT
, ErrorMessage : {"errors":[{"message":"A team owner must be provided when creating a team in application context.","errorCode":"Unknown"}],"operationId":"39f128277056db4890848f3237a8a9e2"}
Inner error:
AdditionalData:
date: 2022-07-22T05:13:12
request-id: a00949aa-9f58-4684-9232-33e8f139537d
client-request-id: a00949aa-9f58-4684-9232-33e8f139537d
ClientRequestId: a00949aa-9f58-4684-9232-33e8f139537d
-------

Microsoft Security | Microsoft Graph
0 comments No comments

Answer accepted by question author

ShivaniRai-MSFT-7217 2,751 Reputation points
2022-07-22T09:25:01.267+00:00

HI @Anonymous ,

As per your error description I can see you are using application permission to create a team and when issuing a request with application permissions, a user must be specified in the members collection. Please follow this documentation.

Use request body like below:

GraphServiceClient graphClient = new GraphServiceClient( authProvider );  
  
var team = new Team  
{  
	DisplayName = "My Sample Team",  
	Description = "My Sample Team’s Description",  
	Members = new TeamMembersCollectionPage()  
	{  
		new AadUserConversationMember  
		{  
			Roles = new List<String>()  
			{  
				"owner"  
			},  
			AdditionalData = new Dictionary<string, object>()  
			{  
				{"******@odata.bind", "https://graph.microsoft.com/v1.0/users('0040b377-61d8-43db-94f5-81374122dc7e')"}  
			}  
		}  
	},  
	AdditionalData = new Dictionary<string, object>()  
	{  
		{"******@odata.bind", "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"}  
	}  
};  
  
await graphClient.Teams  
	.Request()  
	.AddAsync(team);  

Hope this helps.

If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Ben Hamed Sirin (Student) 0 Reputation points
    2023-11-10T11:15:17.2366667+00:00

    J'ai une erreur au niveau de cette ligne il n'a pas accepté le Request() et si je l'élimine il ne marche pas aussi(j'utilise .net c# comme langage de programmation).

     await graphClient.Teams[createdTeam.Id].Members
         .Request()
         .AddAsync(user1);
    

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.