An error getting when i try to send a message to microsoft teams channel by using Graph API

Alwin James 1 Reputation point

Hi team,

I have created a console application in .NET core. I have installed Microsoft Graph into this application by using NuGet Packet manager. I got an error ("UnAuthorized") when I try to send a message to Microsoft teams channel . I mentioned by sample code below,

AzureGraphAuthConfig config = AzureGraphAuthConfig.ReadFromJsonFile("appsettings.json");
IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder

            ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
            graphClient = new GraphServiceClient(authProvider);

            var chatMessage = new ChatMessage
                Body = new ItemBody
                    Content = "Hello Team"

            var res = await graphClient.Teams[teamId].Channels[channelId].Messages.Request().AddAsync(chatMessage);

Getting an error When I execute this code. But working fine from Graph explorer.
Could you please suggest a proper solution for this?


Microsoft Graph Teamwork API
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
2,098 questions
0 comments No comments
{count} votes