question

jvdlinden avatar image
1 Vote"
jvdlinden asked jvdlinden commented

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

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://docs.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",
"conversationIdentityType@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-graph-notifications
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JeffV-4802 avatar image
3 Votes"
JeffV-4802 answered jvdlinden commented

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:

 "conversationIdentityType@odata.type": "#Microsoft.Teams.GraphSvc.conversationIdentityType",
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

This worked. Thanks for the fix!

1 Vote 1 ·

Thanks for the fix.

I have also updated the code snippet within my blogpost :)
https://www.expiscornovus.com/2019/05/29/mention-a-channel-with-flow

1 Vote 1 ·

Works like a charm, again. Thanks all!

1 Vote 1 ·
EuanMurray-5575 avatar image
0 Votes"
EuanMurray-5575 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.