woocommerce / wc-api-ruby

A Ruby wrapper for the WooCommerce API.
MIT License
69 stars 73 forks source link

400 Bad Request using Oauth #21

Closed teelu closed 8 years ago

teelu commented 8 years ago

Having a really strange issue but I'm not sure how to recreate the issue. My client has a woocommerce site using 2.5.5. When connecting using oauth, any request that I attempt to make from my server will get a 400 bad request.

After investigation into what causes this issue it seems like the culprit is:

    def do_request method, endpoint, data = {}
      url = get_url(endpoint, method)
      options = {
        format: :json,
        verify: @verify_ssl,
        headers: {
          "User-Agent" => "WooCommerce API Client-Ruby/#{WooCommerce::VERSION}",
          "Content-Type" => "application/json;charset=utf-8",
          "Accept" => "application/json"
        }
      }
      if @is_ssl
        options.merge!(basic_auth: {
          username: @consumer_key,
          password: @consumer_secret
        })
      end
      options.merge!(body: data.to_json) if data
      HTTParty.send(method, url, options)
    end

When it merges the data.to_json it seems to encode the body as "{}"

perhaps modifying the line to be options.merge!(body: data.to_json) if data.present will be a better approach since "{}" will always be truthy

teelu commented 8 years ago

Using wrong version. bundler kept install .10 instead of .12