I'm trying to send an adaptive card with mentions in powershell using the following code:
$bodyJson = ConvertTo-Json -Depth 8 @{
type = "message"
attachments = @(
{
contentType = "application/vnd.microsoft.card.adaptive"
contentUrl = null
content = {
$"$schema" = "http://adaptivecards.io/schemas/adaptive-card.json",
type = "AdaptiveCard"
version = "1.2"
body = @(
{
type = "TextBlock",
text = "Test <at>Irvin</at>"
}
)
msteams = {
entities = @(
{
type = "mention"
text = "<at>Irvin</at>"
mentioned = {
id = "myMail"
name = "Irvin Dominin"
}
}
)
}
}
})
}
Invoke-RestMethod -uri $URITEST -Method Post -body $bodyJson -ContentType "application/json; charset=utf-8"
As response I'm getting:
Invoke-RestMethod : The page was not displayed because the request entity is too large. Invoke-RestMethod -uri $URITEST -Method Post -body $bodyJson -Con ... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
If I try to change the depth I'm getting:
Webhook message delivery failed with error: Microsoft Teams endpoint returned HTTP error 413 with ContextId MS-CV=x1G81VkCIEWfRHXA/Qv5Aw.0..
CodePudding user response:
Looks like you are mixing PowerShell and json syntax..
Did you by any chance mean
$bodyJson = ConvertTo-Json -Depth 8 @{
type = "message"
attachments = @(
@{
contentType = "application/vnd.microsoft.card.adaptive"
contentUrl = $null
content = @{
schema = "http://adaptivecards.io/schemas/adaptive-card.json"
type = "AdaptiveCard"
version = "1.2"
body = @(
@{
type = "TextBlock"
text = "Test <at>Irvin</at>"
}
)
msteams = @{
entities = @(
@{
type = "mention"
text = "<at>Irvin</at>"
mentioned = @{
id = "myMail"
name = "Irvin Dominin"
}
}
)
}
}
})
}