6

I've done many integrations so far but none of them required sending an HTTP request with the 'DELETE' method. And today, surprise - HTTP method DELETE doesn't support output appears in my log when I try to make this call.

I couldn't find any related questions/answers on this error apart from this.

The code is simple:

Http h = new Http ();

httpRequest = new HttpRequest ();
httpRequest.setEndpoint('https://somedomain.com/api/deleteRecord/recordId');
httpRequest.setMethod('DELETE');
httpRequest.setBody('');

h.send(httpRequest);

The documentation says that the DELETE method is supported too, though there isn't any additional information on this.

Is there a different way of implementing this method or is there something obvious that I'm missing here?

2
  • any good answer for this? I also have this problem when delete a record to other server.
    – rpm07
    Commented Feb 12, 2015 at 6:06
  • @robertpeter07 As you can see from the answers, you are not allowed to set the body in a delete request. Commented Feb 12, 2015 at 23:32

2 Answers 2

9

I'd suggest you need to avoid the call to setBody() when making a DELETE call

I doubt DELETE permits an http body of any size.

2

Since I had the code in a static method, I was setting the body to whatever comes in the parameter.

If you ever get this problem, avoid setting the body:

if (String.isNotBlank(body))
{
    httpRequest.setBody(body);
}

Worked like a charm!

1
  • This doesn't seem clear to me.
    – rpm07
    Commented Feb 12, 2015 at 6:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .