Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

HTTP REST API Delete Method

yad_achyut
Giga Guru

Does Servicenow Support Request Body for Delete Method ? While Sending the Request to 3rd party with HTTP  Delete function using Rest Message API?

5 REPLIES 5

Benjamin A
Mega Sage

Hello @yad_achyut,

 

ServiceNow Outbound REST messages do support the DELETE HTTP method. To set the method to DELETE in a script, do the following:

 

 

var request  = new sn_ws.RESTMessageV2();        
request.setHttpMethod('delete');

var body = "<Message body content>";
request.setRequestBody(body);

 

 

Full documentation on the RESTMessageV2 API can be found here.

@Benjamin A  But this is not working i am getting an error saying the {a non-empty request body is required.

Could you please elaborate on exactly what you are trying to do? I was able to run the following as background script without any issues.

var request  = new sn_ws.RESTMessageV2();        
request.setHttpMethod('delete');
request.setEndpoint('https://webhook.site/1eb5c739-e641-43cb-986c-51bc50dc7c0d'); // Website to test webhooks
request.setRequestHeader('content-type', 'application/json');
var body = "{field: test}";
request.setRequestBody(body);
var response = request.execute();
gs.info(response.getStatusCode());

Hi Benjamin,

This also wont work as REST in snow doesn't allow body for DELETE Methods