# com.sun.jersey.api.MessageException when using Http::DELETE method

**URL:** <https://forums.sketchup.com/t/com-sun-jersey-api-messageexception-when-using-http-delete-method/81804>\
**Category:** Ruby API\
**Tags:** error, json, http, request, delete\
**Created:** [November 22, 2018, 10:26am UTC](https://forums.sketchup.com/t/com-sun-jersey-api-messageexception-when-using-http-delete-method/81804 "2018-11-22T10:26:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Finfa811](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/finfa811/32/28617_2.png) [@Finfa811](https://forums.sketchup.com/u/Finfa811)\
**Post date:** [November 22, 2018, 10:26am UTC](https://forums.sketchup.com/t/com-sun-jersey-api-messageexception-when-using-http-delete-method/81804/1 "2018-11-22T10:26:38Z")

</div>

I have been using the [SketchUp Http module](http://ruby.sketchup.com/Sketchup/Http.html) for a few time, and honestly it works very nice, but recently I have found an issue that I am not able to fix.

I’m trying to send a DELETE request to a server using its RESTful API. The code is something like:

```
url = 'https://myUrl/myApi'
headers = { 'Authorization' => myToken, 'Content-Type' => 'application/json' }
payload = [{ 'id' => myId1, 'details' => myDetails1 }, { 'id' => myId2, 'details' => myDetails2}]

request = Sketchup::Http::Request.new(url, Sketchup::Http::DELETE)
request.headers = headers
request.body = payload.to_s

request.start do |req, res|
  status = res.status_code
  body = JSON.parse(res.body)
  if status == 204
      # Do whatever
  else
      UI.messagebox('Error ' + status.to_s)
  end
end

```

I’m getting a HTTP 400 Bad Request and an _errorcode: INVALID\_OPERATION_ in the response body, with the following message:

> “message” : "com.sun.jersey.api.MessageException: A message body reader for Java class java.util.List, and Java type java.util.List\<com.gehrytech.gteam.core.common.dto.ObjectDto\>, and MIME media type application/octet-stream was not found. The registered message body readers compatible with the MIME media type are:\napplication/octet-stream → com.sun.jersey.core.impl.provider.entity.ByteArrayProvider…

And a list of compatible body readers.

I did some tests:

- I tried the same call with Postman and it’s working

- If I use POST or GET as methods in the same request, the response status is a HTTP 200 OK.

- I tried DELETE with a different API request with no payload, and the response is correct (HTTP 204).

- I tried a different API request that uses POST, but has the same payload (array of hashes), and the response is correct (HTTP 200).

So I guess the issue comes when having an array in the payload (java.util.List) and using the method DELETE.

Any hint? I tried to migrate this specific request to Net/Http but sometimes is taking ages to get the response, so it’s not really efficient.

---

<div class="post-metadata">

**Author:** ![Aerilius](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@Aerilius](https://forums.sketchup.com/u/Aerilius)\
**Post date:** [November 22, 2018, 12:44pm UTC](https://forums.sketchup.com/t/com-sun-jersey-api-messageexception-when-using-http-delete-method/81804/2 "2018-11-22T12:44:36Z")

</div>

[com.sun.jersey](https://jersey.github.io/) is a RESTful web service framework for Java. SketchUp does not include Java, the error occurs not on client-side, but on the server.

It must be specific to the URL to which you send the request.

- If you have access to the web service, check its logs.
- If not:
  - check the documentation whether you use the REST API correctly. Do you send the correct MIME-type? Try an example REST call that should work.
  - contact the administrator of the web service or provider of the API

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [November 22, 2018, 7:10pm UTC](https://forums.sketchup.com/t/com-sun-jersey-api-messageexception-when-using-http-delete-method/81804/3 "2018-11-22T19:10:46Z")

</div>

Your “Content-Type” is set to JSON, but you are not creating a JSON string with `Array#to_s`.

Try …

```ruby
request.body = payload.to_json

```

---

<div class="post-metadata">

**Author:** ![Finfa811](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/finfa811/32/28617_2.png) [@Finfa811](https://forums.sketchup.com/u/Finfa811)\
**Post date:** [November 23, 2018, 8:59am UTC](https://forums.sketchup.com/t/com-sun-jersey-api-messageexception-when-using-http-delete-method/81804/4 "2018-11-23T08:59:58Z")

</div>

@DanRathbun still get the same error. Actually with `Array#to_s` is working well with the rest of calls I tried.

---

<div class="post-metadata">

**Author:** ![Finfa811](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/finfa811/32/28617_2.png) [@Finfa811](https://forums.sketchup.com/u/Finfa811)\
**Post date:** [November 23, 2018, 9:06am UTC](https://forums.sketchup.com/t/com-sun-jersey-api-messageexception-when-using-http-delete-method/81804/5 "2018-11-23T09:06:50Z")

</div>

@Aerilius I did contacted them, and waiting for response.

The weird thing is the same call is working in Postman, so they will probably tell me the problem is on the code.

But using the same code, and just changing

`request = Sketchup::Http::Request.new(url, Sketchup::Http::DELETE)`

to

`request = Sketchup::Http::Request.new(url, Sketchup::Http::POST)`  
or  
`request = Sketchup::Http::Request.new(url, Sketchup::Http::GET)`

returns a status HTTP 200, and not a HTTP 400. So it seems the code is ok too.
