Unable to Post a Message to Teams Channel with Graph API Client + C#

2025-01-24T13:18:50.09+00:00

Hi,

We are trying to post a message to teams channel, with Channel.SendMessage delegated permissions.

And here is the code snippet.

var options = new OnBehalfOfCredentialOptions

{

 AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
``` };

 var oboToken =""

 var onBehalfOfCredential = new OnBehalfOfCredential(

tenantId, clientId, clientSecret, oboToken, options);


 var requestBody = new ChatMessage

 {

Body = new ItemBody

{

 ContentType = BodyType.Html,

 Content = teamsCardData,
``` },
``` };

 var result = await graphClient.Teams[{ teamId}].Channels[{channelId}].Messages.PostAsync(requestBody);
.NET
.NET
Microsoft Technologies based on the .NET software framework.
4,069 questions
Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
10,741 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,887 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,238 questions
{count} votes

Your answer

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