Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to post a multi line json string as body in curl inside bash script

Tags:

json

bash

curl

I have the following 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 invalid json error on post. What am i missing?

like image 422
user330612 Avatar asked Oct 16 '15 02:10

user330612


1 Answers

This worked

curl -H "Content-Type: application/json" -X POST -d "$body" https://dev.cloudapp.net/v1/
like image 175
user330612 Avatar answered Sep 20 '22 18:09

user330612