Invoice API - Ruby SDK - DELETE

Trying to delete a DRAFT invoice, but the request / response doesn’t seem to be using JSON? Using the square-ruby-sdk - below are the _request and _response objects from the Square library.

Unsure what or where the Content-Type is being set to x-www-url-form-encoded, vs JSON - immediately prior to this code, I’m successfully executing the Get Invoice call.

web | #<Square::HttpRequest:0x0000000112a03260 @http_method=“DELETE”, @query_url=“”, @headers={“accept”=>“application/json”, “Authorization”=>“Bearer REMOVED”, “user-agent”=>"Square-Ruby-SDK/ (2022-06-16) ruby/3.1.2 (x86_64-darwin21) ", “Square-Version”=>“2022-06-16”}, @parameters={}, @context={}>

web | #<Square::HttpResponse:0x00000001129e2308 @status_code=415, @reason_phrase=“Unsupported Media Type”, @headers={“date”=>“Fri, 09 Dec 2022 22:07:17 GMT”, “content-type”=>“text/plain; charset=utf-8”, “transfer-encoding”=>“chunked”, “connection”=>“keep-alive”, “x-frame-options”=>“SAMEORIGIN”, “x-xss-protection”=>“1; mode=block”, “x-content-type-options”=>“nosniff”, “x-download-options”=>“noopen”, “x-permitted-cross-domain-policies”=>“none”, “referrer-policy”=>“strict-origin-when-cross-origin”, “vary”=>“Accept”, “cache-control”=>“no-cache”, “x-request-id”=>“27974331-f9e4-422c-b63f-daf1c523fbde”, “x-sq-dc”=>“sjc2b”, “x-sq-region”=>“sjc2b”, “strict-transport-security”=>“max-age=631152000; includeSubDomains; preload”}, @raw_body=“Unrecognized content-type="application/x-www-form-urlencoded", supported: application/x-protobuf, application/json\n”, @request=#<Square::HttpRequest:0x0000000112a03260 @http_method=“DELETE”, @query_url=“”, @headers={“accept”=>“application/json”, “Authorization”=>“Bearer REMOVED”, “user-agent”=>"Square-Ruby-SDK/ (2022-06-16) ruby/3.1.2 (x86_64-darwin21) ", “Square-Version”=>“2022-06-16”}, @parameters={}, @context={}>>

The team is looking into this. :slightly_smiling_face:

1 Like

Updated the Square.rb gem (and related Faraday gems) to the latest ( and still experiencing this issue.

Right, this is an issue that the team is working on. It’s an issue with the SDK. The REST endpoint works as expected however the SDK it’s handling the call correctly. I’ll be sure to post any updates once I get them. :slightly_smiling_face:

1 Like

Hi @dwrowe!

We tracked down the issue and have implemented a fix, but it won’t be released until January 19th.

In the meantime you can follow these instructions to unblock your issue:

  1. In your Ruby project edit your square gem in your Gemfile to this:

    # gem 'square.rb'
    gem 'square.rb', github: 'square/square-ruby-sdk', branch: 'jbergero/patch-fix-delete'
  2. Reinstall your Gemfile with bundle install

  3. Run your program bundle exec rake run

Depending on how you have your repo set up these instructions may differ, but the key piece here is changing your gem file to use this branch jbergero/patch-fix-delete that has the fix.

On January 19th, you can then remove this new line, and uncomment the gem 'square.rb' line and reinstall the package

I’ll post a comment on this post on the 19th as a reminder

Let us know if you have any issues!

Ah - that makes sense. Nice fix. I’d fixed locally in the Faraday client check for a GET providing a body, since I know the spec allows for DELETEs to have bodies, I didn’t see any use of bodies in the code.

^^ for reference - but I prefer your fix, being more explicit and in-line with the future use of the specification.

Hey @dwrowe,

Just posting as a reminder that we released Version of the Ruby SDK today which brought in our fix for the Delete! So you can remove any local changes you made and update to the latest version of the Ruby SDK to get the fix.

Thanks again so much for reporting the issue and providing explicit details, it helped a lot!


Hi Jordan! Apologies for reviving an old topic - it looks like this issue has regressed in the latest version of the Ruby SDK. I’m still digging, but commenting out a similar line from last time with Faraday (with respect to the request having a body on the DELETE call) is resulting in an issue where the Square API is assuming it should be expecting form-url-encoded values instead of JSON.

Last fix was here - fix: successful deletes in ruby sdk · square/square-ruby-sdk@59604d2 · GitHub

Would it be better to open an issue on the GitHub repo?

Hi @dwrowe!

Sorry for the late reply, I just returned from PTO, but I will take a look at this today, and let you know what I uncover!

Thanks for bringing this to our attention!


Hi @dwrowe

We just released a new version of the ruby SDK on Sept. 25. I have confirmed this issue is fixed with this release

Let me know if you have a different experience

Thanks - will run some tests here shortly.

Reviewing the commit logs - nothing for Invoices or the general connection handling was changed - so Faraday wouldn’t have changed either? Can you confirm what the fix was?

I see the fix was applied upstream in this commit - GitHub - apimatic/faraday-client-adapter/commit/28e4243b2e3de3a66725f4ec95397473512ed8fa - which the new SDK release depends on, thus fixes the core issue (and why nothing specific to the requests changed in the Square SDK). Posting this here, for future me to find when Googling :smiley: