Microsoft Teams - Post Channel message with at mention - Invalid request body was sent

Joost van der Linden 126 Reputation points
2021-06-22T12:49:15.217+00:00

Hi all,

I am trying to post a message to a Microsoft Teams channel that includes a Channel at-mention.
https://www.expiscornovus.com/2019/05/29/mention-a-channel-with-flow/

I am using this endpoint: https://learn.microsoft.com/en-us/graph/api/channel-post-messages?view=graph-rest-1.0&tabs=http

I have configured the appropriate permissions, but the service responds with: "Bad Request - 400 "message": "Invalid request body was sent." "
Graph Explorer does the same, of course.
To make it even weirder, last Friday it still worked.

This is my request URL: POST v1.0 https://graph.microsoft.com/v1.0/teams/6530784c-xxxx-xxxx-xxxx-8dae44cbd6eb/channels/19:7c924xxx24904xxx9xxx8a0f279xxx3c@thread.tacv2/messages

This is my request body:

{
"body": {
"content": "<at id=\"0\">General</at> test",
"contentType": "html"
},
"mentions": [
{
"id": 0,
"mentionText": "General",
"mentioned": {
"conversation": {
"id": "19:7c924xxx24904xxx9xxx8a0f279xxx3c@thread.tacv2",
"displayName": "General",
"******@odata.type": "#Microsoft.Teams.GraphSvc.conversationIdentityType",
"conversationIdentityType": "channel"
}
}
}
]
}

I tried encoding the id as included in the Body, doesn't help.

Hope some can help.

Thanks!
Joost

Microsoft Security | Microsoft Graph
0 comments No comments
{count} vote

Accepted answer
  1. Jeff V 91 Reputation points
    2021-06-22T18:32:26.6+00:00

    I've been experiencing this as well for a little while and thankfully came across this post today.

    https://stackoverflow.com/questions/68039885/graph-api-badrequest-on-sending-channel-messages-with-mention

    Remove this from your payload and it should work:

    "******@odata.type": "#Microsoft.Teams.GraphSvc.conversationIdentityType",
    
    3 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Euan Murray 6 Reputation points
    2021-06-22T16:36:00.96+00:00

    Just noticed this too. We use the API for automating messages into Teams and alerting that team via the channel notification

    It's been working for a few years but seems to have broken in the last few days. All testing points to the channel notification formatting causing the POST to be rejected as invalid body type

    0 comments No comments

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.