I want to add a team and add members at the same time. using graph api, c#

Brass Contributor

I want to make a team and immediately add members .

 

I use this code when make a team.

 

   var additionalData = new Dictionary<string, object>()
                {
                    {"template@odata.bind", "https://graph.microsoft.com/beta/teamsTemplates('educationClass')"},
                    {"owners@odata.bind", new List<string>()},
                };
                (additionalData["owners@odata.bind"] as List<string>).Add("https://graph.microsoft.com/v1.0/users/" + ownId);

                
                var team = new Team
                {
                    DisplayName = displayName,
                    Description = description,
                    AdditionalData = additionalData

                };

                await graphClient.Teams
                    .Request()
                    .AddAsync(team);

                
                await Task.Delay(3000);

 

It does not return the team ID.

I've been getting a team ID as the display name of the team.

Do it this way, sometimes I can't bring team id.
Because there is a delay at the time the team is made.

 

I want to add a team and add members at the same time.
Is there a way to create a team and immediately get an ID returned?

Thanks..

1 Reply

@BoHyun - It takes sometime to get the Team created and that is the reason you are getting null id in return. Best way is to separate the logic of creating team and adding members/owners.