How to resolve 'curl: option --data-raw: is unknown' error
Asked Answered
I

2

6

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.

Invincible answered 2/1, 2023 at 11:50 Comment(3)
Can you try running the command by pasting the JSON without line breaks?Breadstuff
Also it looks like your JSON payload is invalid. There is an unexpected , after the "type": "divider" objectBreadstuff
removing , after "type" section didnt resolve the issue. But replacing --data-raw with just --data worked.Invincible
B
15

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 string EOF on a new line, NOT indented. The portion between the EOFs 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).

Barrera answered 2/1, 2023 at 11:57 Comment(1)
Replacing --data-raw with --data resolved the issue. I tried to use <<EOF but it was throwing invalid_payloadcurl: (3) unmatched brace in URL position 1: { ^Invincible
A
0

I had same problem the reason for error was corrected by

Removing backslash \

Replacing --data-raw to --data

Keeping header and other keys till starting of json in single line

instead of following

curl --location 'https://reqres.in/api/users' \
--header 'Content-Type: application/json' \
--data-raw

to

curl --location 'https://reqres.in/api/users' --header 'Content-Type: application/json' --data '{ 
"json":"body" 
}'

I took following from postman throws error as following

curl: option --data-raw: is unknown curl: try 'curl --help' or 'curl --manual' for more information'

curl --location 'https://reqres.in/api/users' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "morpheus",
    "job": "leader",
    "code": {
        "page": 1,
        "per_page": 6,
        "total": 12,
        "total_pages": 2,
        "data": [
            {
                "id": 1,
                "email": "[email protected]",
                "first_name": "George",
                "last_name": "Bluth",
                "avatar": "https://reqres.in/img/faces/1-image.jpg"
            }
        ],
        "support": {
            "url": "https://reqres.in/#support-heading",
            "text": "To keep ReqRes free, contributions towards server costs are appreciated!"
        }
    }
}'

same data is corrected now and is working fine

curl --location 'https://reqres.in/api/users' --header 'Content-Type: application/json' --data '{
    "name": "morpheus",
    "job": "leader",
    "code": {
        "page": 1,
        "per_page": 6,
        "total": 12,
        "total_pages": 2,
        "data": [
            {
                "id": 1,
                "email": "[email protected]",
                "first_name": "George",
                "last_name": "Bluth",
                "avatar": "https://reqres.in/img/faces/1-image.jpg"
            }
        ],
        "support": {
            "url": "https://reqres.in/#support-heading",
            "text": "To keep ReqRes free, contributions towards server costs are appreciated!"
        }
    }
}'
Abecedarium answered 20/9, 2023 at 15:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.