I am using newman to run some tests and I am trying to post this results either to discord or slack.
here is the output in my console (I can't control the formatting, it just prints this way...)
┌─────────────────────────┬──────────┬──────────┐
│ │ executed │ failed │
├─────────────────────────┼──────────┼──────────┤
│ iterations │ 2 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ requests │ 52 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ test-scripts │ 52 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ prerequest-scripts │ 0 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ assertions │ 1813 │ 36 │
├─────────────────────────┴──────────┴──────────┤
│ total run duration: 10.1s │
├───────────────────────────────────────────────┤
│ total data received: 146KB (approx) │
├───────────────────────────────────────────────┤
│ average response time: 157ms │
└───────────────────────────────────────────────┘
What I am trying to do:
# call newman
local output=$(newman run mycollection.postman_collection.json)
# output verbose file
echo "$output"
curl -i -H "Content-Type: application/json; charset=UTF-8" -X POST -d '{"content":"```'"$output"'```"}' https://discordapp.com/api/webhooks/blablabla
Although echo "$output"
prints the table on the console, I get:
{"code": 50006, "message": "Cannot send an empty message"}
However, if I replace
"content":"This is a string"
It works as expected.
How can I send this output table in curl body
The first step would be to simplify the quoting to
The second would be to use
jq
(or a similar JSON tool) to generate the JSON correctly (meaning, anything in the result of$output
would be correctly quoted):