Skip to content

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

@paxer

Description

@paxer

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions