Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call restapi in .sh file

Tags:

linux

I am trying to create a script to call restapi endpoint but I am getting "bad substitution" error.

Here is my script:

vi script.sh
echo "welcome to the script"
echo ${"http://web-integ000/sampleProject/getProductList"}

but when I execute the curl command at commandline it worked.I used the following command

$ curl -H "Accept:application/json" http://web-integ000/sampleProject/getProductList

and I got the following output:

[ {
  "productId" : "u1604028-5948abd0-0",
  "prodcutName":"H1ACX",
  "calendarDate" : "2017-06-20"
  }
 ]timeStamp:1497968810

How to get the response from the restapi using script?

like image 436
madhu Avatar asked Dec 06 '25 08:12

madhu


1 Answers

You can use a simple curl command to get the response from the server as follows:-

rest.sh

result=$(curl -X GET --header "Accept: */*" "http://localhost:9090/employees")
echo "Response from server"
echo $result
exit

Hope it works! Thanks!

like image 192
Arun Kumar N Avatar answered Dec 08 '25 22:12

Arun Kumar N