Sorry if this has been answered but I've been googling for a while and can't seem to find anything. I'm wondering how to send a GET & POST in the same cURL payload if that's possible? In other words, send a GET request from one website's API (in my case returns json data) and then have this post to another application all in the same request. Basically I'm trying to do the same sort of thing that IFTTT does, for ex. when API-a posts news story, then post news story to API-b.
Basically, I can currently send a payload of the text for the url that I'm trying to get to a webhook, but what I'd like to do is have the payload GET the info from a URL then POST this to another url. Is this possible in the same payload?
No, it is not possible with HTTP.
You need to first get the results of the first transfer and then send that to the next one, but you can indeed do that in a single command line if you'd like. Something like this:
curl http://1.example.com/get.html | curl -d#- http://2.example.com/post.php
Related
This is probably a stupid question but I'm pretty out of my depth here. I'm trying to utilize an API for my business, and while most of the API has the parameters in the form of "site?param1=one¶m2=two", one of them does not. Instead it's in the form
required parameters -> key
optional parameters
params: a key-value array of where clauses for the query
I would love to be able to put the parameters in directly in the link, but I'm not sure how to parse this or if it's possible.
Example
https://thepetresorts.gingrapp.com/api/v1/animals?key=KEY¶ms=[{animal_id=1},{name=Charlie}]
This is the example they provided using cURL, but I'm really not interested in actually programming with the API, I just need to make specific pulls every once in a while, and I cannot for the life of me figure out how to utilize cURL.
curl "https://{your-subdomain-here}.gingrapp.com/api/v1/animals" \
-H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \
--data-urlencode "params[month(from_unixtime(birthday))]=11" \
--data-urlencode "key={your-key-here}"
Any advice would be extremely appreciated!
If you're working with an API, it's even better if you can use POSTMAN or INSOMNIA.
The API your describing has two types of requests, GET and POST - the GET request is usually used to "get to view" but occasionally some use it to also modify and push data - this uses parameters within the URL (what you described), POST however is generally used to push data into the body to make a modification, the parameters are posted within the body of the request instead of in the actual URL like GET requests.
You won't be able to modify the endpoint (unless its your own) you will need to GET where its needed and POST when its needed, the POST request will likely deny a GET request as it's not the intended method - you can create a jump page (your own API) to accept GET parameters and generate a POST request to your API - as #muklis mentioned POSTMAN is great you can create the request in there, generate the code in any language and use that to produce a simple PHP page or so that'll take in $_GET[] variables and pass them into the generated POSTMAN request - it's probably your best bet.
-- Edit
You can also use Zapier, forgot about that - Zapier is amazing for easy code-less integrations; you can use the Webhook zap to receive your parameters in repost them in two easy steps within the zap.
Just another idea for you.
What's the best way to send multiple parameters on a REST GET resource call. Normally we can call GET call with path param &/ query however the number of character is limited on a URL so any suggestion or best practice on how to achieve this.
This can be achieved via POST where sending the query in request body as JSON and use json converter on the resource end. I am thinking POST mayn't be a right approach for query or get service from a resource.
I search the existing questions on this but didn't get any proper answer.
Thanks in advance.
You can send a limited data with GET and even the data is visible in URL making data vurnerable. When you use POST data is a alot more safer than GET and you can send large no. of request parameters. You can checkout this link
I have been given a url .. www.abc.com/details and asked to send my name and phone number on this url using POST. They have told me to set the content-type as application/json and the body as valid JSON with the following keys:
name: name of the user
phone number: phone number of the user
Now i have no clue how to send this request! Will it be something like:
http://www.abc.com/details?method=post&name=john&phonenumber=445566
or do i have to use java to send the same?
Please help
Based on what you provided, it is pretty simple for what you need to do and you even have a number of ways to go about doing it. You'll need something that'll let you post a body with your request. Almost any programming language can do this as well as command line tools like cURL.
Once you have your tool decided, you'll need to create your JSON body and submit it to the server.
An example using cURL would be (all in one line, minus the \ at the end of the first line):
curl -v -H "Content-Type: application/json" -X POST \
-d '{"name":"your name","phonenumber":"111-111"}' http://www.example.com/details
The above command will create a request that should look like the following:
POST /details HTTP/1.1
Host: www.example.com
Content-Type: application/json
Content-Length: 44
{"name":"your name","phonenumber":"111-111"}
You can post data to a url with JavaScript & Jquery something like that:
$.post("www.abc.com/details", {
json_string: JSON.stringify({name:"John", phone number:"+410000000"})
});
It is not possible to send POST parameters in the URL in a straightforward manner. POST request in itself means sending information in the body.
I found a fairly simple way to do this. Use Postman by Google, which allows you to specify the content-type (a header field) as application/json and then provide name-value pairs as parameters.
You can find clear directions at [2020-09-04: broken link - see comment] http://docs.brightcove.com/en/video-cloud/player-management/guides/postman.html
Just use your URL in the place of theirs.
You can use postman.
Where select Post as method.
and In Request Body send JSON Object.
In windows this command does not work for me..I have tried the following command and it works..using this command I created session in couchdb sync gate way for the specific user...
curl -v -H "Content-Type: application/json" -X POST -d "{ \"name\": \"abc\",\"password\": \"abc123\" }" http://localhost:4984/todo/_session
If you are sending a request through url from browser(like consuming webservice) without using html pages by default it will be GET because GET has/needs no body. if you want to make url as POST you need html/jsp pages and you have to mention in form tag as "method=post" beacause post will have body and data will be transferred in that body for security reasons. So you need a medium (like html page) to make a POST request. You cannot make an URL as POST manually unless you specify it as POST through some medium. For example in URL (http://example.com/details?name=john&phonenumber=445566)you have attached data(name, phone number) so server will identify it as a GET data because server is receiving data is through URL but not inside a request body
In Java you can use GET which shows requested data on URL.But POST method cannot , because POST has body but GET donot have body.
I am trying to replicate a post I have captured in Fiddler, I have one variable that is in what looks like JSON and I dont know how to replicate this in a POST string.
I have (from Fiddler):
{"var1":"string1", "params":{"1":"string2", "2":50, "3":50, "4":"string3"}, "var2":"string4"}
So my question is how do I represent the "params" variable in a POST url?
Currently I have ...[URL]?var1=string1&(PARAM STUFF)&var2=string4. What do I put in the PARAM STUFF place?
Thanks!
Im trying to retrieve the URL for a facebook users profile pic. The call returns the JSON I expect as per http://developers.facebook.com/docs/reference/api/using-pictures/#json with one problem - if I specify callback=profile I get a /**/ at the start of the line. Unfortunately this is causing the JSON parser (lift-json) I am using to throw an exception.
Is there a way to stop the /**/ being returned? It seems odd but I cant see any reason its happening and thus see no way to turn it off.
The problem I am facing is shown below using curl.
andrews-MacBook-Pro:~ doctorb$ curl "http://graph.facebook.com/582931709/picture?redirect=false&type=normal"
{"data":{"url":"http:\/\/profile.ak.fbcdn.net\/hprofile-ak-ash4\/274518_582931709_901337157_s.jpg","is_silhouette":false}}
andrews-MacBook-Pro:~ doctorb$ curl "http://graph.facebook.com/582931709/picture/redirect=false&type=normal&callback=profile"
/**/ profile({"data":{"url":"http:\/\/profile.ak.fbcdn.net\/hprofile-ak-ash4\/274518_582931709_901337157_s.jpg","is_silhouette":false}});
Your first request is for simple JSON and your second request is for a JSONP formatted response.
Facebook adds a comment at the beginning of their JSONP response to prevent a vulnerability called "JSONP hijacking" in the web browser. As any requests to graph.facebook.com will include Facebook cookies, the comment will prevent malicious websites from simply including the request in a script tag and surreptitiously acting on behalf of the authenticated user.
If you want to use the JSONP request, instead of the simple JSON request, you will need to strip out the comment at the beginning of the response before passing it along to your JavaScript parser.