I want to send a message to certain team and channel in Microsoft Teams through Graph API. I registered my application on Azure Active directory and added multiple permissions.
Additonally, I was trying to follow instructions : https://learn.microsoft.com/en-us/graph/api/chatmessage-post?view=graph-rest-1.0&tabs=http. I get an error in code :
How can I add Microsoft 365 Subscription to my created tenant. Microsoft's guidelines are not very helpful.
The error "Teams is disabled for the tenant. Ensure the tenant has a valid Office365 subscription" usually occurs if the user is not assigned with O365 license.
To resolve the error, make sure to subscribe to Microsoft 365 subscription. Refer this MsDoc.
Then Go to Azure Active Directory -> Users -> Licenses -> Assignments -> Select Office 365 -> Save
Make sure Microsoft Teams is enabled:
After assigning the required licenses, I am able to Send chatMessage in a channel successfully via Microsoft Graph API like below:
https://graph.microsoft.com/v1.0/teams/TeamsID/channelChannelID/messages
Content-type: application/json
{
"body": {
"content": "Hello World"
}
}
To do the same in C#, refer the below code snippet:
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new ChatMessage
{
Body = new ItemBody
{
Content = "Hello World",
},
};
var result = await graphClient.Teams["{team-id}"].Channels["{channel-id}"].Messages.PostAsync(requestBody);
Reference:
Unable to create Team using MS-Graph API - Microsoft Q&A by CarlZhao-MSFT