How to POST request using curl with authentication - bash

I have API http://x.xx.x.xx:xxxx/api/v1/clusters/Cluster12/commands/restart for restarting cluster.
I want to use the next command:
curl --request POST 'http://x.xx.x.xx:xxxx/api/v1/clusters/Cluster12/commands/restart'
But got the message "Full authentication is required to access this resource"

You could try:
curl -u username:passwd -X POST 'http://x.xx.x.xx:xxxx/api/v1/clusters/Cluster12/commands/restart'

With Variables:
curl --data "var1=val1&var2=val2" http://x.xx.x.xx:xxxx/api/v1/clusters/Cluster12/commands/restart
Without Variables:
curl -X POST http://x.xx.x.xx:xxxx/api/v1/clusters/Cluster12/commands/restart
May be you can use this?

Thanks for help. Now it is working. I should use some arguments from API
curl -u username:password -H "Accept: application/json" -X POST -d '{"SomeArgument":"true"}' http://masterIP:xxxx/api/v1/clusters/Cluster12/commands/restart

Related

Cannot import Jelastic Manifest with cURL command using two -H parameters

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\"}"

API Platform - Dev - all requests return empty result

I have set up API platform and am trying to test the API using curl, eg.
curl -X POST -H "Content-Type: application/json" http://localhost/authentication_token -d '{"email":"test#test.com","password":"the_new_password"}'
curl http://localhost/docs
I am getting no response from the server, always blank.
Requests needed to be HTTPS, as it seems HTTP requests are simply thrown away / ignored. Add the -k flag since the certificate will be self signed and CURL will error out.
curl -X POST -H "Content-Type: application/json" https://localhost/authentication_token -d '{"email":"test#test.com","password":"the_new_password"}' -k
curl https://localhost/docs -k

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 #-

How to create an Order using Square Connect API?

I tried the following request to create an order using Square Connect's Orders API (https://docs.connect.squareup.com/api/connect/v1/#navsection-orders). The response I got back was "not found". I wonder if I am missing anything in my request?
Request:
curl -H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer repace-with-real-access-token" \
-d '{}' \
https://connect.squareup.com/v1/locationId/orders
Response:
{"type":"not_found","message":"NotFound"}
If this is not the correct way to create an order, can you please let me know how to do it using Square Connect API?
Thanks!
Remove the -d '{}'. The endpoint takes GET requests and by default, this argument will make curl send POST instead of GET requests.

Stormpath cURL Error

I am trying to follow this example: http://docs.stormpath.com/rest/quickstart/
One of the steps mentions to do the following cURL request:
curl -X POST --user $YOUR_API_KEY_ID:$YOUR_API_KEY_SECRET \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{
"name" : "My Awesome Application"
}' \
'https://api.stormpath.com/v1/applications?createDirectory=true'
I am using online cURL from : http://onlinecurl.com/
Here is the snapshot of the curl request:
Here is the snapshot of the Header Response:
Can anybody please tell me what is wrong?
I'm also having problems with that tool. I tried what you show in your screenshot, plus some other combinations. I actually get a different error (media type unauthorized). I suspect this tool uses some kind of proxy that is messing with the request.

Resources