I am trying to run shell script with a curl command as below with --data-raw as body.
curl --location --request POST '<URL>' \
--header 'Content-Type: application/json' \
--data-raw '{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Help Text",
"emoji": true
}
},
{
"type": "divider"
},
]
}'
Output:
curl: option --data-raw: is unknown
curl: try 'curl --help' or 'curl --manual' for more information
I couldn't find any error with the json validator. Please suggest a solution. TIA.
CodePudding user response:
Here, you have 2 issue.
- your JSON is invalid, the
,
line 14 need to be removed - use
--data
and a heredoc :
curl --location --request POST '<URL>' \
--header 'Content-Type: application/json' \
--data "@/dev/stdin"<<EOF
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Help Text",
"emoji": true
}
},
{
"type": "divider"
}
]
}
EOF
Here documents:
cat <<EOF
followed by several lines of text, followed by the literal stringEOF
on a new line, NOT indented. The portion between theEOF
s is passed to the command as standard input. If'EOF'
is 'quoted', substitutions WON'T be done; otherwise they are. See<<-
for the indented variety (not recommended, need TABs).