Send JSON using curl from bash script when JSON path supplied as variable

1

I just cannot understand why all my attempts failing. I try to use curl to send POST request with json to specific url when a path to JSON defined as variable:

#!/bin/sh

JSON_TMP=/home/aaa/jsons/make_6h_from_1h.json
curl -X POST -H "Content-Type: application/json" --data-binary "@${JSON_TMP}" http://some-url

Whatever I tried (putting "@${JSON_TMP}" or "@$JSON_TMP" or @"${JSON_TMP}" or whatever else) just does not seems to work!

What is more annoying is that there are no any error messages or something - I just run command and get prompt back again. On other end I can see that no json was sent.

kaytrance

Posted 2018-03-29T11:38:58.800

Reputation: 123

Were you trying to use JsonPath in your url? – IgorGanapolsky – 2018-04-27T13:53:21.893

"just does not seems to work" - is there an error on the server side? What about the query doesn't work? Does -v give you more information? – Attie – 2020-02-09T15:05:20.867

Answers

0

The following works:

body_arg=(--data-binary @${filePath})

curl -X POST -H "Content-Type: application/json" "${body_arg[@]}"  http://some-url

user3478489

Posted 2018-03-29T11:38:58.800

Reputation: 1

0

curl -X POST -i -H "Accept: application/json" -H "Content-Type: application/json" --data-binary --data-binary @${JSON_TMP} http://some-url

Try with removing double quotes across @${JSON_TMP}

sukumar c

Posted 2018-03-29T11:38:58.800

Reputation: 1