0

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?

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

Comments

0

I use the one that answered by @pafjo and it works fine for me but I need to add some message and also use variable in the same message, in this case use the following curl

'$' curl -H 'Content-Type: application/json' -d "{\"text\": 'Repo \"$REPO_NAME\" already exists'}" https://incomingwebhookurl

here repo name is my variable that I pass when ever I trigger github actions using workflow_dispatch

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.