How to get data with curl - http

I have a page which i need to submit a number and after that i get data from that number
page is like:
http://page/
and after submit form request URL changes to:
http://page/services/getData
but method is something like:
http://page/services/getData?method=search&1234
can someone helped me to pull data showed in http://page/services/getData?method=search&1234 with curl?
I've already tried:
curl -v -H "Content-Type: application/json" -X POST \ -d http://page/services/getData?method=search&1234
curl -o http://page/services/getData?method=search&1234
curl --data http://page/services/getData?method=search&1234

I was looking for hours but i just posted the question and i get what i wanted:
curl --request GET --url 'http://page/services/getData?method=search&1234'

Related

How can I convert a HTTP request to curl?

I'm newbie on this so I would like your help, according to CrazyCall docs I want to test those code examples in terminal using CURL, for example this one:
GET /api/v1/users HTTP/1.1
x-api-token: your-secret-api-key
Account: your-account-hash.crazycall.com
Host: api.crazycall.com
I tried to convert to curl and execute like this:
curl -XGET -H 'x-api-token: mdsRFGRV23XXXXXXX' -H 'Account: lopDOPLSVXXXX.crazycall.com' -H 'Host: api.crazycall.com' /api/v1/users
But it shows me a message <url> malformed
I also added "Content-type: application/json" header but it's still the same.
How can I fix it?
Prepand the protocol and domain (https://api.crazycall.com) to your path (/api/v1/users):
curl -X GET -H 'x-api-token: mdsRFGRV23XXXXXXX' -H 'Account: lopDOPLSVXXXX.crazycall.com' -H 'Host: api.crazycall.com' https://api.crazycall.com/api/v1/users

WordPress 4.7 REST API Example Request does not work

I'm using successfully the WordPress 4.7 REST API in this way:
curl -H "Authorization: Basic mykey" -X POST --data-urlencode "title=Something" www.myhost.com/wp-json/wp/v2/posts/770
The example in the new docs suggests:
curl -X POST http://demo.wp-api.org/wp-json -d '{"title":"My New Title"}'
which obvious is a wrong endpoint. Adapting to
curl -H "Authorization: Basic mykey" -X POST www.myhost.com/wp-json/wp/v2/posts/770 --data-urlencode '{"title":"My New Title"}'
does not change the title but simply returns the post as JSON
Any idea?
Came over my own question, which I did resolve a long time ago. Just if someone struggles with this too.
First of course, posting data with curl requires the -d option an not the --data-urlencode. Second, the REST endpoint needs to know the type of data. Here JSON. So setting the correct Content Type is essential.
This is a complete example:
curl -H "Authorization: Basic mykey>" -H "Content-Type: application/json" -X POST -d '{"title":"Something"}' www.myhost.com/wp-json/wp/v2/posts/770

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/

How can I use the Pingdom API to pause and resume checks from bash?

I'm writing a quick and dirty deployment script and would like to disable and reenable a Pingdom check as part of it. How do I do that using something like cURL?
To pause a check:
curl -X PUT -u 'your#email:yourpassword' -H 'Content-Type: application/json' -H 'App-Key: yourapplicationkey' -d 'paused=true' https://api.pingdom.com/api/2.0/checks/checkid
To resume a check:
curl -X PUT -u 'your#email:yourpassword' -H 'Content-Type: application/json' -H 'App-Key: yourapplicationkey' -d 'paused=false' https://api.pingdom.com/api/2.0/checks/checkid
Replace your#email with your pingdom email.
Replace yourpassword with your pingdom password.
Replace yourapplicationkey with a generated key from the "Sharing" section in your account.
Replace checkid with the numeric ID you see in the browser URL when you click on your check in the Pingdom UI.
You can also use modern way - just API key instead of using also email/password.
First, generate your own API key in https://my.pingdom.com/app/api-tokens and then you can use curl commands like for pausing:
curl -X PUT \
https://api.pingdom.com/api/3.1/checks \
-H 'Authorization:Bearer YOURAPIKEY' \
-d 'paused=true&checkids=777'
or for resuming:
curl -X PUT \
https://api.pingdom.com/api/3.1/checks \
-H 'Authorization:Bearer YOURAPIKEY' \
-d 'paused=false&checkids=777'
Replace YOURAPIKEY with your real API key and 777 with valid check ID.
checkids can be also omitted, then all checks will be modified.

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

Resources