I have write a shell script which we are calling an API. I now have to trigger a SQL(SELECT) query using shell script. I have to pass that outcome to the POST API. Instead of GET call, I need to trigger POST call. Whatever it the output of the SQL Query(which is a metric value, I need to use it in Rest call.
Can anyone guide how to trigger a SQL query and use that in Rest Call?
https://https://postman-echo.com/get?test=123 (Test URL)
Body:
[
{
"V_1": "test",
"V_2": "test01",
"V_3": "test03",
"V_4": "1"
}
]
This is the shell script which I tried.
#!/bin/sh
res=$(curl --netrc-file ~/.netrc https://postman-echo.com/get?test=123)
echo "Response Received"
echo $res
exit
CodePudding user response:
To solve this, you would need to run the shell script to perform the SQL query and then pass the query result to the Rest call using the request body. For example:
#!/bin/sh
# Execute the SQL query
res=$(curl --netrc-file ~/.netrc https://sqlserver.com/query)
# Pass the result of the SQL query to the Rest call
curl -X POST https://postman-echo.com/get -d "{\"V_1\": \"$res\"}"