Add user in Teams group/channel.

New Contributor

I have 2 string values a user and Teams group , how do I add a user in the teams group using c#?

1 Reply

@nellietheelephant 

Hello, nellietheelephant, here is the answer to your question:

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var conversationMember = new AadUserConversationMember
{
        Roles = new List<String>()
        {
                "owner"
        },
        AdditionalData = new Dictionary<string, object>()
        {
                {"email address removed for privacy reasons", "https://graph.microsoft.com/v1.0/users('8b081ef6-4792-4def-b2c9-c363a1bf41d5')"}
        }
};

await graphClient.Teams["{team-id}"].Members
        .Request()
        .AddAsync(conversationMember);

If you need more details on how to add a member to a team using the user principal name or other options, check this documentation. In case you are interested in important tips for Microsoft 365 administrators, check this page here.