How to put json multiline string as body in curl inside bash script

I have a bash script

#!/bin/bash body=$(cat << EOF { "CreatedBy": "$(hostname -f)", "Id": "$(uuidgen)", "Type": "TestAlertType", "AlertCategory": "NonUrgent" } EOF ) curl -H "Content-Type: application/json" -X POST -d $body https://dev.cloudapp.net/v1/ 

But I get an invalid json error in the message. What am I missing?

+8
json bash curl
source share
1 answer

It worked

 curl -H "Content-Type: application/json" -X POST -d "$body" https://dev.cloudapp.net/v1/ 
+10
source share

All Articles