I am trying to send multi-line comment in the curl body from bash script. Below is my curl invocation.
#!/bin/bash
temp="This is sample data: 2019/05/21 03:33:04
This is 2nd sample data: #2 Sample_Data"
response=$(curl -sS --location "${HEADERS[@]}" -w "%{http_code}\n" -X POST "$url" --header 'Content-Type: application/json' \
--data-raw "{
\"id\" : \"111\",
\"status\" : {
.
.
.
\"details\" : [ \"$temp\" ]
}
}")
echo "$response"
In the actual script the variable temp is stdout. So, it will be a multi-line output.
If I try above script I get below error:
{"exceptionClass":"xxx.exception.MessageNotReadableException","errorCode":"xxx.body.notReadable","message":"The given request body is not well formed"}400
Can anyone please let me know what is the issue and how to fix it?
Thanks in advance
\"details\" : [ \"$temp\" ]. Iftempis single line then it's working fine..$tempstring needs to be JSON encoded, so the multiline data is the issue. I'm pretty sure there is a duplicate question somewhere.