multipart POST with nested params cUrl - ruby-on-rails

I'm trying to test making a post request with cURL passing a file into nested params, but having a hard time getting the flags/ordering correct:
curl -i -H "Authorization: <access_str>" -H "Accept: application/json"
-H "Content-Type: application/json" -X POST -d '{"data": {"photo":
"#/Users/colin/Desktop/mastiff.jpg"} }' localhost:3000/api/v1/blah/blah
I feel like I either need a --data-binary or -F or both maybe? The server is just getting the nested params as a string and not as a multipart file
{"data"=>{"photo"=>"#/Users/colin/Desktop/mastiff.jpg"}

curl -i -H "Authorization: <access_str>" -X POST -F
'data[photo]=#/Users/colin/Desktop/mastiff.jpg'
localhost:3000/api/v1/data/data/data
Don't even need to specify that it's JSON. Next step is trying to pass two photos in the same field. The problem now is that passing a second file results in a massive binary string.

Related

Bash CLI with HTTParty and rails to handle multiple headers one of which includes a slash

The following connects to the API's server
httparty -a post -H Content-Type:application/json "https://test.co.uk/interface/search"
and returns an error message (which is by design).
However, if another header is added:
httparty -a post -H Content-Type:application/json -H Accept-Encoding:gzip,deflate "https://test.co.uk/interface/search"
an error occurs in the ruby JSON parser
.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/json-2.1.0/lib/json/common.rb:156:in
`parse': 765: unexpected token at '' (JSON::ParserError)
No amount of escaping with quotes changes the situation.
httparty -a post -H 'Content-Type:application/json' -H Accept-Encoding:gzip,deflate "https://test.co.uk/interface/search"
same error...
On the other hand, if one excludes the 'application/json' header, multiple headers can be submitted, obtaining a server response (same error message from API server).
httparty -a post -H Accept-Encoding:gzip,deflate -H Content-Length:578 -H Host:test.co.uk -H Connection:Keep-Alive "https://test.co.uk/interface/search"
How can multiple headers be submitted, with the 'application/json' string pass ruby's JSON parsing filter?
Personally I use HTTPie, try to curl like this way.
curl -H "Accept-Encoding:gzip,deflate" \
-H "Content-Length:578" \
-H "Host:test.co.uk" \
-H "Connection:Keep-Alive" \
-X POST \
"https://test.co.uk/interface/search"

In Apache Ranger, how to create service in hdfs-plugin with Rest Api call?

I am trying to create a service in hdfs-plugin. I am refering this link.
I have tried below curl command:
curl -H "Content-Type: application/json" -X POST -d '{"configs": {"password": "*****","username": "admin"},"description":"hdfsservice","isEnabled": true,"name": "hadoopdev","type": "test","version": 1}' http://localhost:6080/service/public/v2/api/service
When I ran this it didn't give any response, not even any error.
Can someone help me to know if this is the correct curl or not?

Wget to download excel from Jira automatically

I have tried the below commands to get the excel file automatically from jira but I'm getting different data other than the filter data.
wget --user username--password pass -O test.xls --ignore-length=on http://esjirq62.emea.nsn-net.net:8080/sr/jira.issueviews:searchrequest-excel-all-fields/70920/SearchRequest-70920.xls?tempMax=1000;
curl -D my-output.xml -u upgrade:hjjKl801 -X GET -H "Content-Type: application/json" http://esjirq62.emea.nsn-net.net:8080/sr/jira.issueviews:searchrequest-excel-all-fields/70920/SearchRequest-70920.xls?tempMax=1000
Please help me here.
You have to set correct encoding header gzip :
curl -D my-output.xml -u upgrade:secret -X GET -H "Content-Type: application/json" -H "Accept-Encoding: gzip" "http://esjirq62.emea.nsn-net.net:8080/sr/jira.issueviews:searchrequest-excel-all-fields/70920/SearchRequest-70920.xls?tempMax=1000"
Some notes:
Remove password from your example
-D flag for curl dumps headers, not output. Did you mean -o maybe?
Content-Type header can be skipped
To be on the safe side, put the url in double quotes
You can copy request from Google Chrome using developer tools
I can't get Wget work in my environment (permission denied error; maybe because of SSO?) but following curl command .
"D:\DSUsers\uid41890\Tools\curl.exe" -o C:\Users\uid41890\Documents\JIRA\search.csv -u uid41890:password -X GET "http://jiraurl:port/sr/jira.issueviews:searchrequest-csv-current-fields/17899/SearchRequest-17899.csv"
No need for Header options as mentioned in #grundic's answer.
Replace -D by -o in your original command and change the output file format from xml to csv for example.
You must use -O flag as:
curl -o excel.xls -O -u upgrade:hjjKl801 -X GET -H "Content-Type: application/json" http://esjirq62.emea.nsn-net.net:8080/sr/jira.issueviews:searchrequest-excel-all-fields/70920/SearchRequest-70920.xls?tempMax=1000

Invalid token error in Linkedin Gem when its work in CURL of Rails app

When i used CURL post from console then its work but when i used linkedin gem method in controller then its not working and get error regarding access token. Where is wrong here not findout.
CURL Code
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"comment":"hello from google www.google.com! http://ibm.com","visibility":{"code":"anyone"}}' https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=AQVxxxxJXygzp_8Exxxxg7_7FaxxxxxxtWzBXAxxxxxa5z1MVK6-kubHJ5JIaGAxxxx234wndpAMc_CxmCsIHxxxxraleZqkU0t_WNEhxxxz8_cKpeOixxxxsd15-X-MdvzYVxxxx9hQ&format=json&title=linkedin HTTP/1.1
LinkedIn gem code
client = LinkedIn::Client.new(
config[:your_consumer_key],
config[:your_consumer_secret]
)
client.authorize_from_access(
config[:oauth_user_token],
config[:oauth_user_secret]
)
client.add_share(
comment: 'Good Morning',
content: {'submitted-url' => 'http://www.github.com/blazeeboy' }
)
Any one have a idea where is wrong here.
============= UPDATE =============
system 'curl -H "Content-Type: application/json" -H "authToken: auth_token" --data '{"comment":"hello from google www.google.com! http://google.com","visibility":{"code":"anyone"}}' https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=AQVxxxxygzp_8E3ySvg7_7FahixxxxxxtWzBXAja5OQ8a0wta5z1MVK6-kubHJ5JIxxxxwndpAMc_CxmCsIHxFlexxxxxleZqkU0t_WNxxxxmi7CMz8_cKpexxxx15-X-MdvzYVOxxxxm9hQ&format=json&title=linkedin HTTP/1.1'
Thanks
curl -H "Content-Type: application/json" -H "authToken: auth_token" --data '{}' https://api.linkedin.com/v1/people/~/shares
Try running this :
system "curl -H 'Content-Type: application/json' -H 'authToken: auth_token' --data '{'comment':'hello from google www.google.com! http://google.com','visibility':{'code':'anyone'}}' https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=AQVxxxxygzp_8E3ySvg7_7FahixxxxxxtWzBXAja5OQ8a0wta5z1MVK6-kubHJ5JIxxxxwndpAMc_CxmCsIHxFlexxxxxleZqkU0t_WNxxxxmi7CMz8_cKpexxxx15-X-MdvzYVOxxxxm9hQ&format=json&title=linkedin HTTP/1.1"
In rails when you use double quotes inside single quotes it gives error with some commands.
OR you can try like this :
`curl -H 'Content-Type: application/json' -H 'authToken: auth_token' --data '{'comment':'hello from google www.google.com! http://google.com','visibility':{'code':'anyone'}}' https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=AQVxxxxygzp_8E3ySvg7_7FahixxxxxxtWzBXAja5OQ8a0wta5z1MVK6-kubHJ5JIxxxxwndpAMc_CxmCsIHxFlexxxxxleZqkU0t_WNxxxxmi7CMz8_cKpexxxx15-X-MdvzYVOxxxxm9hQ&format=json&title=linkedin HTTP/1.1`

Weird json request via curl

I'm sending json request via curl to my local web server
curl -H 'Content-Type: application/json' -d {"name":"Stanford University", "subdomain":"stanford"} http://localhost:3000/rest/v1/groups.json
But in my rails app in params i'm getting
Parameters: {"name"=>"Stanford University", "subdomain"=>"stanford", "group"=>{"name"=>"Stanford University", "subdomain"=>"stanford"}}
Where did that hash group came from, and how do i controll it?
Look in config/initializers/wrap_parameters.rb. You likely have wrap_parameters enabled for JSON requests.
You can disable this option in the above file with
wrap_parameters false
Recommended Reading: http://api.rubyonrails.org/classes/ActionController/ParamsWrapper.html
You have to send it into Json Format
Try Following
curl -H 'Content-Type: application/json' -d "{\"name\":\"Stanford University\", \"subdomain\":\"stanford\"}"
OR
hash = {"name":"Stanford University", "subdomain":"stanford"}
curl -H 'Content-Type: application/json' -d "#{hash.to_json}" http://localhost:3000/rest/v1/groups.json

Resources