Curl GET request is not giving any output in body - shell

Via Postman the Api which i am using is:-
https://myCertManager.com/api/pik/restapi/MyCerts?INPUT_DATA={"operation":{"details"{"Cert_Name":"cert1"}}}
with authtoken in header "AUTHTOKEN: XXXX-XXXX-XXXX-XXXX"
When I send the get request via postman I get my certificate in the response body which is correct
Now I need to fetch this cert via curl command, so I created these two commands but when I execute them they connect to the server but the body of the response is coming empty.
curl -g -k -v -X GET https://myCertManager.com/api/pik/restapt/MyCerts?INPUT_DATA={"operation":{"details"{"Cert_Name":"cert1"}}} -H "AUTHTOKEN: XXXX-XXXX-XXXX-XXXX"
curl -k -v -X GET https://myCertManager.com/api/pik/restapt/MyCerts -H "AUTHTOKEN: XXXX-XXXX-XXXX-XXXX" -d "INPUT_DATA={"operation":{"details"{"Cert_Name":"cert1"}}}"

In postman if its working , you can generate equalent curl command by clicking the code button on the right to[ corner , it will create the curl code snipet for you

The issue was because the GET parameter doesn't support -d parameter. So this type of code will never work.
curl -k -v -X GET https://myCertManager.com/api/pik/restapt/MyCerts -H "AUTHTOKEN: XXXX-XXXX-XXXX-XXXX" -d "INPUT_DATA={"operation":{"details"{"Cert_Name":"cert1"}}}"
Secondly the GET parameter only sends the data through the url itself so the INPUT_DATA needs to be in the URL itself like this one
curl -g -k -v -X GET https://myCertManager.com/api/pik/restapt/MyCerts?INPUT_DATA={"operation":{"details"{"Cert_Name":"cert1"}}} -H "AUTHTOKEN: XXXX-XXXX-XXXX-XXXX"
But the URL dosent support the braces and quotes {} "" and to what i did was converted the INPUT_DATA to the URL format. So the actual working code is this one.
curl -g -k -v -X GET https://myCertManager.com/api/pik/restapt/MyCerts?INPUT_DATA=%7B%22operation%22%3A%7B%22details%22%7B%22Cert_Name%22%3A%22cert1%22%7D%7D%7D -H "AUTHTOKEN: XXXX-XXXX-XXXX-XXXX"

Related

curl with --netrc-file option does not work but with -d it does

I ran into a problem when trying to use curl with --netrc-file option in my bash script. When I just put curl -d "username=MYUSR&password=MYPSWD" https://st-machinexxx/api -c cookies.txt
then it works fine. But curl --netrc-file configfile.txt https://st-machinexxx/api -c cookies.txt
causes a HTTP ERROR 401. What can be the reason? I was trying to set athentication method by adding --digest, --negotiate and --ntlm as well as set some headers, but didn't help. I am using curl 7.29.0, configfile.txt contains just three lines:
machine st-machinexxx
login MYUSR
password MYPSWD

Api curl script is not showing output in my unix terminal

I wrote a curl script to pull data from my api url into my unix terminal. But when I run the script below, I get a blank space as my output, rather than data from the api url. I don't get any standard error message, just a blank space followed by $ to enter a new command.
#!/bin/bash
INSTANCE_NAME="https://servicenow.com/ServiceNowData/tickets?ticks=4320000"
DATA_OUTPUT=$(curl -s -k -X GET -H "accept: application/json" $INSTANCE_NAME)
echo $DATA_OUTPUT
Page 404. And -H "Accept-Encoding: application/json"

Redirect a cURL response to a cURL that POSTs, but not through a file

I 'd like to post directly a json object from a url(json) to another url
so the command goes as follows:
curl "<resource_link>.json" -o sample.json
curl -X POST "<my_link>" "Content-type: application/json" -d #sample.json
I 'd like to avoid this, so what is the solution? Is it something like that?
curl -X POST "<my_link>" "Content-type: application/json" -d "curl <resource_link>.json"
But it does not work? Also, this one post Stream cURL response to another cURL command posting the result
does not explain thouroughly and it is not working
Yes,
curl
manual explains the '#' but it does not explain about using another curl
Alternatievely, if I could save somewhere temporarily the 1st cURL response and use it in the other command(but not in a file)
You don't want -x POST in there so let's start with dropping that.
Send the results from the first transfer to stdout by not using -o, or telling -o to use stdout with -o-, and
Make sure your second transfer accepts the data to send on stdin, by using -d#-.
curl "<link>.json" | curl "<link2>" -H "Content-type: application/json" -d #-
With curl 7.82.0 and later
Starting with curl 7.82.0 you can do it even easier with the new --json option:
curl "<link>.json" | curl "<link2>" --json #-

unable to get the individual values from curl get call

This it my Curl get command
Status=$(curl -X GET -H "ExecutionHistoryID: $guid" -H "Authorization: Bearer $token" $uri/ExecutionStatus/)
The result is as follows:
{"Status":"Running","ExecutionStatus":"Executing","Tasks":[{"Name":"ISMIMD_CNFReporting_DashBoard_EngReport","ExecutionStatus":"","ResourceName":"137.182.160.225","LastReportedError":"","Status":"Executing"}]}
Here how to get status inside the json result?
I need the output as Running or Executing to be printed

Google Geocode api always returns ZERO_RESULTS using CURL

I am trying to use CURL in a bash script to get JSON from Google Geocode, but I can't get it to work with --data-urlencode or --data
this will return ZERO_RESULTS:
curl -k --data "address=berlin&sensor=false" http://maps.googleapis.com/maps/api/geocode/json
however this is successful:
curl http://maps.googleapis.com/maps/api/geocode/json?address=berlin&sensor=false
What am I doing wrong here?
It appears to work when I include -G.
curl -G -k --data "address=berlin&sensor=false" http://maps.googleapis.com/maps/api/geocode/json

Resources