How rails can grab headers of a curl request like:
curl -v -H 'X-Auth-Service-Provider: https://api.twitter.com/1/account/verify_credentials.json' -H 'X-Verify-Credentials-Authorization: OAuth realm="http://api.twitter.com/",
oauth_consumer_key="yTrEIQH6jhtmLUypg8T5", oauth_signature_method="HMAC-SHA1",
oauth_token="514797-YuI8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWTyu",oauth_timestamp="1271323750",
oauth_nonce="oYu6nMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7U9Y",
oauth_version="1.0", oauth_signature="CV4bTfE7Rs9J1kafTGwufLJdspo%3D"' -F "file=#/path/to/file" http://localhost:3000/api/upload.xml
Grab those values: oauth_cosumer, oauth_token, oauth_timestamp etc.
thanks in advance!
headers['oauth_consumer_key']
etc...
Related
JIRA's REST API search doesn't honor maxResults parameter.
curl -o lambrusco.txt -k -D- -u admin:admin -X GET -H "Content-Type: application/json" https://jira.domain.com/rest/api/2/search?jql=assignee=blackpearl&startAt=0&maxResults=4
No matter what maxResults is, it always returns 50 results.
Output:
{"expand":"schema,names","startAt":0,"maxResults":50,"total":61,"issues":[{"expand":"operations,versionedRepresentations,editmeta,changelog,transitions,renderedFields","id":"15588","self": ...}
What am I missing here?
Your request looks fine. Here is example on official Atlassian JIRA, which works fine:
curl -X GET -H "Content-Type: application/json" "https://jira.atlassian.com/rest/api/2/search?jql=assignee=tlay&startAt=1&maxResults=1" | jq -r '.maxResults'
It looks like that it's related to REST API Bug!
You need to quote the request when using curl as shown by #grundic, otherwise the shell will interpred the ampersand. And note that the API is case sensitive.
I try to use OAuth with google. I receive a code using a POST request to this URL:
https://accounts.google.com/o/oauth2/v2/auth
Then I try to get a access token by sending a POST request to this URL:
https://www.googleapis.com/oauth2/v4/token
But this returns me a HTTP 404 "Not found" error. Is this URL wrong?
The URI that I've gotten to work for an Oauth2 token right now is
https://www.googleapis.com/oauth2/v3/token
I saw the same "v4" referenced in documentation, but couldn't get it to work either.
If you're developing your own OAuth 2.0 clients on the Google infrastructure, I'd recommend Google's OAuth 2.0 Playground which takes you through each request and response for their API's.
Oauth has been deprecated by Google. For OAuth 2.0, Try their well-known OpenID Configuration link which shows:
"authorization_endpoint": "https://accounts.google.com/o/oauth2/v2/auth"
This works for me
curl --location --request POST 'https://www.googleapis.com/oauth2/v4/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=1234567891011-t28d34tfmfk5i5865hm7kij8nvl7vdax.apps.googleusercontent.com' \
--data-urlencode 'client_secret=KFcsEpfLjg64ta6TtQ1QibOC' \
--data-urlencode 'grant_type=refresh_token' \
--data-urlencode 'refresh_token=1/gb5fEFSu_iwbvbsXZdK8ddrJjNTD1RrXbQqdsT6wuJK'
It looks newer and it worked when I tried.
https://oauth2.googleapis.com/token
https://developers.google.com/identity/protocols/oauth2/web-server#httprest_3
How do I convert the following CURL PUT request to rspec and test the behaviour of JSON parser.
curl -D - -X PUT --data "not json" -H "Content-Type: application/json" http://localhost:3000
And how to check the response? Thank you in advance.
The best is to use vcr gem https://github.com/vcr/vcr
Simply create script like in https://github.com/vcr/vcr#usage but with proper HTTP request.
VCR.use_cassette("json_test") do
req = Net::HTTP::Put.new('http://localhost:3000', 'not json')
req.content_type = 'application/json'
res = Net::HTTP.get_response(req)
end
With this real HTTP request will be recorded once and in rspec local file will be used instead.
You can use the -i option:
-i, --include
(HTTP) Include the HTTP-header in the output. The HTTP-header includes things like server-name, date of the document, HTTP-version and more...
from http://curl.haxx.se/docs/manpage.html
How i can send request like this via rails
POST /token/ HTTP/1.1
Host: api.admitad.com
Authorization: Basic XXX
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
grant_type=client_credentials&scope=public_data&client_id=XXX
based on admitad api
You can send the POST request via the command line with a tool like cURL:
curl --data-urlencode "grant_type=client_credentials&scope=public_data&client_id=XXX" http://api.admitad.com/token
If you want to use HTTP basic authorization, add the -u option:
curl --data-urlencode "grant_type=client_credentials&scope=public_data&client_id=XXX" http://api.admitad.com/token -u "client_id:public_key"
Another similar command line tool is httpie.org, which uses a slightly different syntax.
I need post file and JSON object to API (Ruby On Rails) by curl in one request.
My request looks like this:
curl --data #file.pdf -H "Accept: application/json" -H "Content-Type: multipart/form-data" -X POST -d '{"document":{"name":"file name"}}' http://localhost:3000/api/documents
But Rails parse it bad. Params on the server:
Parameters: {"{\"document\":{\"name\":\"file name\"}}"=>nil}
Where is problem?
You should pass multipart/form-data (as you specify), not a JSON string. Try this:
-d 'document[name]=file name'
Result on my machine:
Parameters: {"document"=>{"name"=>"file name"}}