Issue
How could I send a JSON-Object via curl to an Incoming Webhook from Microsoft Teams? The JSON is filled with content from a variable.
alarmmeldung=`cat file.txt`
curl -H 'Content-Type: application/json' -d '{"text": $alarmmeldung}' https://incomingwebhookurl
Always I get "Bad payload received by generic incoming webhook" as response.
If I put quotes around the $alarmmeldung
then the request could be sent but I get the text $alarmmeldung. What I actually want is the content of $alarmmeldung.
How I have to write the curl statement?
Solution
You need replace the single quotes with double quotes to get the variable to be interpolated. You also need to add double quotes around the variable so that it valid json.
curl -H 'Content-Type: application/json' -d "{\"text\": \"$alarmmeldung\"}" https://incomingwebhookurl
If you don't want to do handle the escaping, you can also just included the complete json body as a file:
curl -H 'Content-Type: application/json' -d @file.json https://incomingwebhookurl
Answered By - Pafjo Answer Checked By - Timothy Miller (WPSolving Admin)