Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Teams Webhook Generating 400 for Adaptive Card

I have a functioning webhook to a Teams channel to which I can successfully post messages. I am now trying to post an adaptive card to the webhook. Using Postman and performing a Post to https://outlook.office.com/webhook/xyz, with Content-Type set to application/json in the header and the following adaptive card set in the body.

{
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "type": "AdaptiveCard",
  "version": "1.0",
  "speak": "Nothing to say.",
  "body": [
    {
      "type": "TextBlock",
      "text": "Hello Teams' user"
    }
  ]
}

With this I receive a HTTP 400 Bad Request and Summary or Text is required message. Does anyone know if Teams webhooks support Adaptive Cards yet or if this is an unsupported task currently?

like image 374
Gilligan Avatar asked Jun 08 '18 03:06

Gilligan


People also ask

How do you use adaptive cards in Microsoft Teams?

Select New Step. Search for Microsoft Teams, and then select Post an adaptive card to a Teams channel and wait for a response as the action. Select the Team and the Channel to which you'd like to post the card. Paste this JSON into the Message box.

Which of the following component in Microsoft Teams does not support adaptive cards currently?

Media elements are currently not supported in Adaptive Card on the Teams platform.

What are Microsoft Teams adaptive cards?

Adaptive Cards are actionable snippets of content that you can add to a conversation through a bot or message extension. Using text, graphics, and buttons, these cards provide rich communication to your audience. The Adaptive Card framework is used across many Microsoft products, including Teams.

Does Microsoft Teams support Webhooks?

The webhook is available in the Teams channel. You can create and send actionable messages through Incoming Webhook or Office 365 Connector.


1 Answers

I'm using axios to send an Adaptive Card to a Teams Connector and I was getting this same error. In my case, I was able to resolve the issue by wrapping the card as an "attachment" to the message protocol shown in this link (syntax copied here for reference).

https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using?tabs=cURL#send-adaptive-cards-using-an-incoming-webhook

{
   "type":"message",
   "attachments":[
      {
         "contentType":"application/vnd.microsoft.card.adaptive",
         "contentUrl":null,
         "content":{
            "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
            "type":"AdaptiveCard",
            "version":"1.4",
            "body":[
                {
                "type": "TextBlock",
                "text": "For Samples and Templates, see [https://adaptivecards.io/samples](https://adaptivecards.io/samples)"
                }
            ]
         }
      }
   ]
}

By sending the above JSON as the request body (data argument for axios), I successfully got the Adaptive Card to show up in my Teams Channel.

As you can see, the value of "content" is the Adaptive Card structure. The Adaptive Card follows the documented syntax, found here:

https://docs.microsoft.com/en-us/adaptive-cards/authoring-cards/getting-started

https://docs.microsoft.com/en-us/answers/questions/400502/adaptive-cards-with-incoming-webhooks-in-microsoft.html

But ultimately, I found it easier to work with this "Designer" https://www.adaptivecards.io/designer/ which provides a WYSIWYG interface.

I am sending the request to a Connector that I created in Teams by following the instructions found here:

https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook#create-incoming-webhook-1

And now it responds with 200 OK and shows up in the Channel!

like image 120
chris Avatar answered Oct 20 '22 14:10

chris