Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send PUT requests payload with the request body and not as query params #130

Open
paxer opened this issue Aug 21, 2019 · 5 comments
Open

Comments

@paxer
Copy link
Contributor

paxer commented Aug 21, 2019

We have an issue when a customer (via OAuth) trying to update his inventory via Etsy API, we call it like this

::Etsy::Request.put("/listings/123456789/inventory", inventory_data)

inventory_data hash could be pretty big for some listings with lots of products and offerings and Etsy API returns an error from time to time

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>414 Request-URI Too Long</title> </head><body> <h1>Request-URI Too Long</h1> <p>The requested URL's length exceeds the capacity limit for this server.<br /> </p> </body></html>

Etsy support said that we need to send a payload as a request body to avoid this error.

I am digging in to the library code and I see this is happening because params are sent as URL query and not as a request body.

https://github.com/kytrinyx/etsy/blob/master/lib/etsy/secure_client.rb#L76

but the low-level client actually supports body as a param

this is form OAuth AccessToken library which secure_client.rb calling

 def post(path, body = '', headers = {})
   request(:post, path, body, headers)
 end

I've tried to modify the library to send params as a body, following the similar pattern in with post_multipart method https://github.com/kytrinyx/etsy/blob/master/lib/etsy/secure_client.rb#L84

but no matter what I do I always getting an error from Etsy oauth_problem=signature_invalid

My current attempt is


    def put(endpoint, body = '')
      # client.put(endpoint, body) - this returns the same error oauth_problem=signature_invalid

      client = Net::HTTP.new(Etsy.host, 443)
      client.use_ssl = true

      client.start do |http|
        req = Net::HTTP::Put.new(endpoint)
        req.body = body
        add_oauth(req)
        http.request(req)
      end
    end

body here is @parameters.to_json string and endpoint - is a path without query string.

Has anyone run into the same problem?

@paxer
Copy link
Contributor Author

paxer commented Aug 21, 2019

just found a fork with an attempt to handle this issue vbyno@7f433c9 I am trying a very similar approach but unfortunately Etsy API keeps returning me oauth_problem=signature_invalid 🤔

@paxer
Copy link
Contributor Author

paxer commented Aug 21, 2019

@vbyno did you have the same Etsy API error oauth_problem=signature_invalid when you tried your fork? I also noticed that you are sending all_parameters as a hash, while the underlying client expects it as a string, I wonder how it works for you? (It does not for me until I convert hash to a string, but then, again I have oauth_problem=signature_invalid from Etsy API )

@paxer
Copy link
Contributor Author

paxer commented Aug 21, 2019

another attempt here saurabhs-tech@6d0e99b this approach works without oauth_problem=signature_invalid error for me however Etsy inventory API requires a payload in JSON format so when I use this approach I am getting Value for products was not a valid JSON string. and if I change it to json - then I am back to oauth_problem=signature_invalid ...

@saurabhs-tech does it works for you when you update inventories?

@paxer
Copy link
Contributor Author

paxer commented Aug 21, 2019

alright, thanks everybody for the ideas and implementations I figured out a working solution zibbet/etsy@master...zibbet:send_put_request_payloads_with_body

@vbyno
Copy link

vbyno commented Aug 21, 2019

@paxer , If I remember correctly, my approach works because of JSON headers I'm adding to the request. As I see, in your last solution you also add ['Content-Type'] to the request, which might do a trick as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants