i have ruby on rails based api which accepts a get request.
example :
http://localhost:3000/api/search?query=whatis&access_token=324nbkjh3g32423
when i do curl from mac terminal like
curl http://localhost:3000/api/search?query=whatis&access_token=324nbkjh3g32423
i checked in the server with "request.fullpath", it return only "/api/search?query=whatis", the second parameter is missing.
however if i do curl like
curl --data="query=whatis&access_token=324nbkjh3g32423" http://localhost:3000/api/search
it is taking all the parameters.
i understand there is a problem with encoding, but i what to know what difference is there with the two requests.
Thanks in advance
The problem probably is that bash shell sees & as the end of the command.
try quoting the entire querystring like this -
curl "http://localhost:3000/api/search?query=whatis&access_token=324nbkjh3g32423"
Related
When running my own mediawiki on localhost I run into a problem with the api endpoint for editing a page. The api works fine otherwise. For instance when querying tokens I get the following output:
$ curl "http://localhost/api.php?action=query&meta=tokens&type=createaccount|csrf|login&format=json"
{"batchcomplete":"","query":{"tokens":{"createaccounttoken":"1e5c2ce3f9e12fdab05a0e6e6352da3162644214+\\","csrftoken":"+\\","logintoken":"35ee2e6ccbbd654bcfada9cddab07f7662634214+\\"}}}
Interestingly the csrftoken has the strange value '+\\', which also seems to be appended to the logintoken.
When posting an edit action (for an existing page called Alice) with this token I get the reponse that the token is missing from the post body. But it's not missing, or is it?
$ curl -X POST "http://localhost/api.php?action=edit&title=Alice&summary=test&text=article&baserevid=0&token=+\\&format=json"
{"error":{"code":"mustpostparams","info":"The following parameter was found in the query string, but must be in the POST body: token.","*":"See http://localhost/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/> for notice of API deprecations and breaking changes."}}
Then I followed this advice and added the cookie-jar option to make the curl request from the same session, but it gave the same error response. Any ideas?
By the way I used the docker.io/bitnami/mediawiki:1 docker image together with a mariadb to set up my mediawiki.
The following parameter was found in the query string, but must be in the POST body
I'm not very familiar with curl but it seems that you are sending a post request with the params in the query part. Try sending them in the post body as the error suggests:
curl --data "action=edit&title=Alice&summary=test&text=article&baserevid=0&token=+\\&format=json" http://localhost/api.php
This suggests it does :
https://youtube-eng.googleblog.com/2009/10/oembed-support_9.html
But I'm getting nothing back when I do, say
curl "https://www.youtube.com/oembed" -d 'format=json' -d 'url=https://www.youtube.com/watch?v=uXBDgLglFig'
Does anyone know if the oembed API has been deprecated?
You're making a POST request with those options you're passing to curl. You need to make a GET request instead, like so:
curl 'https://www.youtube.com/oembed?format=json&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DuXBDgLglFig'
Note that the URL parameter must be URL encoded. How you do that depends on what language you're using to make the request.
So I just understood that the Slack Web API does not support JSON data over POST. Which means I have to encode my complex and nested JSON object to fit in query parameters over GET. Problem is, the attachements don't seem to work. Does anyone have a solution ?
So I just understood that the Slack Web API does not support JSON data over POST. Which means I have to encode my complex and nested JSON object to fit in query parameters over GET.
I'm not sure I follow what you mean. You can certainly use POST. The body of a Slack API call should be form-encoded, but parameter values are sometimes JSON (as is the case for attachments).
Here's a working curl command that uses HTTP POST to post a message with a simple attachment.
$ curl -d token=<REDACTED> -d channel=<REDACTED> \
-d text="This is the main text." \
-d attachments='[{"text": "This is an attachment."}]' \
https://slack.com/api/chat.postMessage
I'd recommend using POST, but GET also works fine. If you fill in the values in https://api.slack.com/methods/chat.postMessage/test, the tool will give you a URL at the bottom that you can use with HTTP GET.
Is it possible to send a GET and POST request using curl through a linux terminal?
Essentially, I'm trying to understand what these guys are doing in this tutorial but I don't understand how to add additional GET parameters to their tutorial's example.
For instance, in their tutorial (http://valeriobasile.github.io/candcapi/), they use the example of:
curl -d 'Every man loves a woman' 'http://gingerbeard.alwaysdata.net/candcapi/proxy.php/raw/pipeline?semantics=fol'
It works but I want a graphical representation of this. They also mention this in their example Here.
"An entry point to generate a PNG image...
$CANDCAPT/drg
"The URL accepts the same GET parameter as pipeline."
So I tried to send this but it doesn't get a PNG file:
curl -d 'Every man loves a woman&pipeline' 'http://gingerbeard.alwaysdata.net/candcapi/proxy.php/raw/pipeline?semantics=drs&roles=verbnet'
This actually breaks their system.
curl -d 'Every man loves a woman' 'http://gingerbeard.alwaysdata.net/candcapi/proxy.php/raw/pipeline?semantics=drs&roles=verbnet%20%#d%2dbox'
So my question is, I'm not too sure what the developers mean when they say the url accepts the same GET parameters and how would I add that in? Please let me know if you have any ideas, thanks.
EDIT 1 -
I tried adding drg instead of pipeline but it returns a message saying, "not found"
curl -d 'Every man loves a woman' 'http://gingerbeard.alwaysdata.net/candcapi/proxy.php/drg?semantics=fol'
I read through the GitHub documentation, and at the bottom it describes how to obtain graphical output:
The C&C/Boxer API provides an entry point to generate a PNG image of the DRG of a given text:
$CANDCAPI/drg
The URL accepts the same GET parameter as pipeline and returns a raw PNG file.
Based on this, your GET url should look something like this:
http://gingerbeard.alwaysdata.net/candcapi/proxy.php/drg?semantics=fol
Using the "same" GET parameters means that whatever you passed to the pipeline after the question mark can also be passed to the drg web service.
Modified anwser:
Here's the correct command from the same example:
curl -d 'Every man loves a woman' 'http://gingerbeard.alwaysdata.net/candcapi/drg?semantics=fol'
And for people who are beginners like me, here's to save the png file:
curl -d 'Every man loves a woman' 'http://gingerbeard.alwaysdata.net/candcapi/drg?semantics=fol' >> image.png
Hi I'm very new to Grails. I have set of api's that I wish to test. By using curl command I can test those api's like this:
curl --verbose https://x.x.x.in/init_order -u x-x-x-x-x-x-x-B4E4E: -d "amount=400.00" -d "order_id=xxxxxx" -d "customer_id=xxxxx101" -d "customer_email=customer#mail.com"
This will give a response in JSON.
What I want is I need to hit this url. I thought ? is the separtor in params of grails. But when I do something like this:
https://x.x.x.in/init_order/x.x.x.x.x?no=123?no2=234
and print the params, I can see I get no as 123?no2=234. Here the ? is not separating my params.
Very new to Grails, I wonder where I'm making the mistake.
Thanks in advance.
It's not grails specific. In HTTP you use ? to start the parameter list then & to separate the parameters from each other.
The default URL Mapping is /$controller/$action?/$id?
So if you had BookController with an action of findBooks and wanted to pass in parameters author and title it would look like:
http://yourdomain.com/book/findBooks?author=Grisham&title=Firm