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
Related
I am new to shell. I am using curl in my Jenkins job.
I am getting the expected output if I hardcode the payload in the curl request
curl -i -X POST $url --header "'Content-Type: application/json'" --data-raw {"deployed": true}
But when I try and store it as a variable, I see I am getting errors, even though the curl output I get as part of the Jenkins pipeline is exactly the same
payload='{"deployed": true}'
curl -i -X POST $url --header "'Content-Type: application/json'" --data-raw $payload
Need help in understanding how are the different
I'm trying to create a Jelastic Manifest with a cURL command inside it. When I import it, it gives me an error but unfortunately I have no access to the console (disabled by the provider).
The command is the following :
curl -X POST <my_url> -H "Content-Type: application/json" -H "Authorization: Bearer <token>" -d "{}"
Some additionnal information :
The URL is correct 100%
The token does not contain any special characters : Only upper/lowercase characters and numbers
The command is run successfully from the command line
If I remove the first -H parameter, I can import my manifest. Same if I remove the second -H parameter and keep the first one
My guess is that, somehow, having two -H is not considered as valid but I don't know why. Any ideas ?
EDIT : A screenshot of the error shown on the platform
The "two -H parameters" wasn't a root cause in your question.
The thing is that the YAML gets the data you sent as a key/value array (dictionary).
In your example it would be:
curl -s -X POST https://test.com -H "Content-Type - as a key,
and
application/json" -H "Authorization: Bearer xx" -d "{\"Key\":\"Value\"}" - as a value.
If you need an array of strings the YAML may be as this
cmd [cp]:
- 'curl -s -X POST https://test.com -H "Content-Type: application/json" -H "Authorization: Bearer xx" -d "{\"Key\":\"Value\"}"'
If you need a multi-line string it should look like this
cmd [cp]: |
curl -s -X POST https://test.com -H "Content-Type: application/json" -H "Authorization: Bearer xx" -d "{\"Key\":\"Value\"}"
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"
I am trying to get the response code of the curl command to a variable and output of the same curl command in a file. Another curl command within a different function will run and the output should append to the same output file.
response=$(curl -i -H "content-type: application/json" -w "%{http_code}" -u "$id:$cred" -H "Accept: application/json" -X POST http://sitename -d '{'<input>'}' >> out.txt
This is giving me neither the response nor the curl output in the file.
Below is working and gives me response as the desired http code though.
response=$(curl -i -H "content-type: application/json" -w "{http_code}" -u "$id:$cred" -H "Accept: application/json" -X POST http://sitename -d '{'<input>'}'
Echo $response
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 #-