I have been using the SketchUp Http module 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.