I'm trying to access my Magento store's REST API, but I can' seem to acquire the access token. I keep getting a 400 Bad Request (OAuth::Unauthorized) error.

Here's the code I'm using:

require 'oauth'
require 'mechanize'

@m = Mechanize.new

@title = @m.get('').title

@callback_url = ''
@consumer = OAuth::Consumer.new(
  :request_token_path => '/oauth/initiate',
  :site => ''

@session = {}

@request_token = @consumer.get_request_token(:oauth_callback => @callback_url)
@session[:request_token] = @request_token
@session[:authorize_url] = @request_token.authorize_url(:oauth_callback => @callback_url)

@m.get(@session[:authorize_url]) do |login_page|
  auth_page = login_page.form_with(:action => '') do |form|
    form.elements[1].value = 'admin'
    form.elements[2].value  = 'goodfood88'

  authorize_form = auth_page.forms[0]

  callback_page = authorize_form.submit

  puts 'Successfully authorized application' unless callback_page.title != @title

@access_token = @request_token.get_access_token

It returns the following:

    Successfully authorized application
/Users/narzero/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/oauth-0.4.7/lib/oauth/consumer.rb:216:in `token_request': 400 Bad Request (OAuth::Unauthorized)
        from /Users/narzero/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/oauth-0.4.7/lib/oauth/tokens/request_token.rb:18:in `get_access_token'
        from six.rb:37:in `<main>'

I've stored the important data into a Hash, here's what it returns:

# => {:request_token=>
     @http=#<Net::HTTP open=false>,

What could I try to get an access token?

closed as too broad by Marius May 7 '15 at 6:38

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Did you try with php? MAgento is written in php and at least I am not able to understand the ruby syntax, so I think it will hard for us to help. – Fabian Blechschmidt Aug 21 '14 at 12:29

Browse other questions tagged or ask your own question.