How to get http request from curl? - http

I've got a curl request which looks like:
curl -s http://someurl1.com -H 'Accept: application/json' -u 'emv:LgKrAVkFf2c6mr4DFBQUdjBK' -d grant_type='password' -d scope='offline_access' -d username='datafiles#random.com' -d password='456Qwer()' -d acr_values='tenant:sdfdfsdf-e5e7-42d5-9881-sdfsdf' | python -m json.tool
How can I construct a simple HTTP request from it? I've tried to import it with postman but got Error while importing Curl: Zero or Multiple option-less arguments. Only one is supported (the URL)

curl http://someurl1.com -H 'Accept: application/json' -u 'emv:LgKrAVkFf2c6mr4DFBQUdjBK' -d grant_type='password' -d scope='offline_access' -d username='datafiles#random.com' -d password='456Qwer()' -d acr_values='tenant:sdfdfsdf-e5e7-42d5-9881-sdfsdf'
this string can be imported by Postman.

Related

Failing in salt-api

Team,
I'm facing difficulties setting up salt-api.
I'm in a setup ubuntu 16 and CherryPy 3.5. Which is a open bug https://github.com/saltstack/salt/issues/37783 .
I managed to downgrade to CherryPy 3.2.3.
rest_cherrypy:
port: 8000
disable_ssl: True
external_auth: pam:
saltuser:
- .*
Upon salt-api and salt-master restart
curl -k http://localhost:8000
{"clients": ["local", "local_async",
> "local_batch", "local_subset", "runner", "runner_async", "ssh",
> "wheel", "wheel_async"], "return": "Welcome"}
While login or submitting a job I get 401 Unauthorized .
curl -sSk http://localhost:8000/login -H 'Accept: application/x-yaml' -d username=saltuser -d password=passwd -d eauth=pam
curl -vki http://localhost:8000 -H "Accept: application/x-yaml" -d client=local -d tgt='stg-ubuntu102*' -d fun='cmd.run' -d "kwarg": {"cmd": "touch /tmp/mannoj"}
Can someone please guide me here?
In order to execute commands through the Salt API you need either to login while executing the command or passing X-Auth-Token. So what you need to do is to use the token that was generated by executing the login command
First make sure that you have a system user before executing the following
curl -sSk http://localhost:8000/login -H 'Accept: application/x-yaml' -d username=saltuser -d password=passwd -d eauth=pam
In your next request:
curl -vki http://localhost:8000 -H "Accept: application/x-yaml" -H "X-Auth-Token: TOKEN_GOES_HERE" -d client=local -d tgt='stg-ubuntu102*' -d fun='cmd.run' -d "kwarg": {"cmd": "touch /tmp/mannoj"}
Note that I have added -H "X-Auth-Token: TOKEN_GOES_HERE"
For more information check the following page

curl upload file -T

I get the error curl: Can't open 'files=#1.txt'! when trying to run code:
curl -v -XPOST -k -H "Accept: application/json" -T "files=#1.txt" https://192.168.1.102/
any suggestion on how to pass the text file's name properly?
-T is for PUT and wants a file name only:
curl -T 1.txt https://192.168.1.102/
You seem to want to POST a file? If you want it sent "plainly", you probably want:
curl -H "Accept: application/json" --data-binary #1.txt https://192.168.1.102/
If you want to instead send the file as a multipart formpost, you might do it similar to:
curl -F files=#1.txt https://192.168.1.102/

Grep Curl command's console output to a file

Need an help in doing grep of 3 variables from the curl commands console output.
By executing the below curl command i get some output which prints in the console itself. I need to grep some variables(say staus, name, url) and redirect it to a file.
curl -v -X POST -D tmp.txt -H "Content-Type:text/plain" --data "$SECRET" -H "Accept:application/xml" -H "Connection:close" http://google.com/api/search
Some of your responses must be going to stderr, try:
curl ... | grep 'pattern' &> filename
I'd recommending using slightly different options to curl if you want to process the output. If I were looking for the Expires header:
curl -si -X POST -H "Content-Type:text/plain" --data "$SECRET" -H "Accept:application/xml" -H "Connection:close" http://google.com/api/search
If you want the HTTP status, you can just do this:
curl -si -X POST -H "Content-Type:text/plain" --data "$SECRET" -H "Accept:application/xml" -H "Connection:close" http://google.com/api/search | head -1
That'll print HTTP/1.1 301 Moved Permanently -- add an |awk '{print $2}' to the end of that and you'll get only the numeric status.

FireBase, NEST. I can GET, but cannot PATCH using curl. Why am I getting a 400 error?

I am using the url at the developer-api.nest.com site, and my request is re-directed to the firebase-apiserver01...01.dapi.production.nest.com
I get the correct structured data back, using this dos command:
curl -v -k -L -X GET "https://developer-api.nest.com/structures/Za6hCZpmt4g6mBTaaA96yuY87lzLtsucYjbxW_b_thAuJJ7oUOelKA/?auth=c.om2...AeiE"
I get the error 'Invalid content sent' when I send this PATCH
curl -v -k -L -X PATCH "https://developer-api.nest.com/structures/Za6hCZpmt4g6mBTaaA96yuY87lzLtsucYjbxW_b_thAuJJ7oUOelKA/?auth=c.om2...AeiE" -H "Content-Type: application/json" -d '{"away":"home"}'
I have tried adding '.json' before the question mark, but get the same error.
To set the structure to home/away you'll need to send a PUT request for example as follows:
curl -v -L -X PUT "https://developer-api.nest.com/structures/g-9y-2xkHpBh1MGkVaqXOGJiKOB9MkoW1hhYyQk2vAunCK8a731jbg?auth=<AUTH_TOKEN>" -H "Content-Type: application/json" -d '{"away":"home"}'
Hope that helps
--Nagesh

how to do a HTTP POST a list of value using cURL

how I do post multiple values to the same key using cURL?
for example when I ran the following to my example.com URL, it complained...is the format correct or is this a problem with the backend not being able to handle the request?
curl -k -H 'Accept: application/json' --user admin:admin example.com -d name=peter -d name=paul -d name=mary
Multiple -d looks fine. The docs said -d name=daniel -d skill=lousy will generate name=daniel&skill=lousy
http://curl.haxx.se/docs/manpage.html#-d
So if you want send an array, you have to use the [] brackets.
-d name[]=peter -d name[]=paul -d name[]=mary
It looks like you can also use
-d "name[]=peter&name[]=paul&name=mary"

Resources