Forum Discussion
Forward Adaptive Card
How can we forward adaptive cards in teams. Is there any easy way out?
One method which I found was using Graph API. Following the below link with Example 3 : Send a message containing cards :-
https://learn.microsoft.com/en-us/graph/api/chatmessage-post?view=graph-rest-1.0&tabs=javascript#examples
But it has html content, how to add json content to it. Please can anyone help with this?
- ChetanSharma-msftMicrosoftHello Janhvi - Thanks for raising your query.
If you are trying to send the message only in Teams channel, you can also use Incoming webhook via which you can directly send the Adaptive Card as Json:
Reference doc link: https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=dotnet
Please let us know if you need any further help here. - Prasad_Das-MSFTMicrosoft
Hi Janhvi - Could you please let us know if you have any further queries?
- JanhviCopper Contributor
Prasad_Das-MSFT
This webhook seems to be compatible only with channels. But our requirement is to forward adaptive card in a personal chat.- Prasad_Das-MSFTMicrosoft
Janhvi - As you have already mentioned using this API we can send adaptive card to personal chat/group chat or channel.
POST https://graph.microsoft.com/v1.0/chats/{chat-id}/messages { "subject": null, "body": { "contentType": "html", "content": "<attachment id=\"74d20c7f34aa4a7fb74e2b30004247c5\"></attachment>" }, "attachments": [ { "id": "74d20c7f34aa4a7fb74e2b30004247c5", "contentType": "application/vnd.microsoft.card.thumbnail", "contentUrl": null, "content": "{\r\n \"title\": \"This is an example of posting a card\",\r\n \"subtitle\": \"<h3>This is the subtitle</h3>\",\r\n \"text\": \"Here is some body text. <br>\\r\\nAnd a <a href=\\\"http://microsoft.com/\\\">hyperlink</a>. <br>\\r\\nAnd below that is some buttons:\",\r\n \"buttons\": [\r\n {\r\n \"type\": \"messageBack\",\r\n \"title\": \"Login to FakeBot\",\r\n \"text\": \"login\",\r\n \"displayText\": \"login\",\r\n \"value\": \"login\"\r\n }\r\n ]\r\n}", "name": null, "thumbnailUrl": null } ] }
In the above example the request body is already in JSON format. However, it seems like the "content" field in the "attachments" array is a stringified JSON.
As it has html content, you are interested in something easier. So, you can use Power Automate/Flow to send adaptive card in personal chat or channel following below document.Create flows that post adaptive cards to Microsoft Teams - Power Automate | Microsoft Learn
Thanks,
Prasad Das
------------------------------------------------------------------------------------------
If the response is helpful, please click "**Mark as Best Response**" and like it. You can share your feedback via Microsoft Teams Developer Feedback link. Click here to escalate.