Home > Enterprise >  Calling an API with curl does not work: curl http://server/api?k1=v1&k2=v2
Calling an API with curl does not work: curl http://server/api?k1=v1&k2=v2

Time:04-25

I would like to call an API from a BASH script. When I can call an API for first two links it works but I don't get the same result for the two last ones (they work in a browser)

echo "Kuma null"
curl --silent https://status.lol.net/api/push/UGUH?msg=OK > /dev/null
sleep 5
echo "Kuma not null"
curl --silent https://status.lol.net/api/push/UGUH?msg=OK
sleep 5
echo "Pi-hole null"
curl --silent http://192.168.0.22:5555/admin/api.php?disable=600&auth=54 > /dev/null
sleep 5
echo "Pi-hole not null"
curl --silent http://192.168.0.22:5555/admin/api.php?disable=600&auth=54
sleep 5

Output:

Kuma null
Kuma not null
{"ok":true}Pi-hole null
[]Pi-hole not null
[]

What do I need to change?

CodePudding user response:

curl --silent http://192.168.0.22:5555/admin/api.php?disable=600&auth=54

You need to quote the URL like this:

curl --silent "http://192.168.0.22:5555/admin/api.php?disable=600&auth=54"

Otherwise it'll be interpreted as

curl --silent http://192.168.0.22:5555/admin/api.php?disable=600 & auth=54
#                                                               ^^^^^^^^^^
  •  Tags:  
  • bash
  • Related