12

I can get information from an Oauth2 API by:

token = "Token I get from authenticating my App"
auth = "Bearer " + token
user = HTTParty.get("API Website", :headers => { "Authorization" => auth})

How would I post to that API content generated in my app? I have an instance variable:

@contact = {"contact": {"name": "John Doe"  }}

I tried this:

token = "Token I get from authenticating my App"
auth = "Bearer " + token
user = HTTParty.get("API Website", :headers => { "Authorization" => auth}, @contact)

to no avail.

Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
shicholas
  • 6,123
  • 3
  • 27
  • 38

1 Answers1

14

Answered my own question

HTTParty.post("API Website", :headers => { "Authorization" => auth}, :body => "@contact")
shicholas
  • 6,123
  • 3
  • 27
  • 38
  • Was the problem that you needed to `post` instead of `get`, or that you needed to add the key `:body` to the post request? – stytown Feb 11 '16 at 22:30
  • I believe it was the body key. nowadays though I use and strongly recommend the Net::HTTP library that's in the ruby standard lib, http://ruby-doc.org/stdlib-2.3.0/libdoc/net/http/rdoc/Net/HTTP.html#method-i-post because I have come to realize that the less dependencies I have in an app the better. – shicholas Feb 12 '16 at 21:58