The CreatorCon Call for Content is officially open! Get started here.

HTTP REST API Delete Method is not working

srinidhi
Tera Guru

Hello All,

 

Unable to delete record in 3rd party tool with HTTP delete method. Getting below mentioned error.

"{\"type\":\"https://tools.ietf.org/html/rfc7231#section-6.5.4\",\"title\":\"Not Found\",\"status\":404,\"traceId\":\"00-7e78b735d2000a98d9dff502b5d1810a-6cc4e5d7d061b472-00\"}"
Regards,
Srinidhi.
 
Here is my script.
 

 

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
try { 
 var r = new sn_ws.RESTMessageV2('Machine Users', 'Delete Machineuser');
 
 var body = {
	"id": 118206,
	"clientId": 1510,
 };
 r.setRequestHeader('Content-Type', 'application/json');
 r.setRequestBody(JSON.stringify(body));

 var response = r.execute();
 var responseBody = response.getBody();
 var httpStatus = response.getStatusCode();
 gs.addInfoMessage('response status:' + httpStatus );
 gs.addInfoMessage(JSON.stringify(responseBody));
}
catch(ex) {
 var message = ex.message;
}
})(current, previous);

 

1 ACCEPTED SOLUTION

Thanks all for the help,

I have modified the end point URL in the rest message and in script I added the parameters.

Now it's working fine. Below are the changes.

 

script:

var assid = current.u_assignment_id;

var r = new sn_ws.RESTMessageV2('Users', 'Delete Machineuser');
 r.setStringParameterNoEscape('clientId', '1511');
 r.setStringParameterNoEscape('id', assid);
var response = r.execute();
 
Rest message endpoint for delete method:
 

 

View solution in original post

17 REPLIES 17

@srinidhi 

Did you try hitting their endpoint from Postman with DELETE and content body?

If it works from postman then you can determine/debug why it's not working from ServiceNow.

How does their body look like?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

They are looking for parameters not request body i think.

 

srinidhi_0-1699350858190.png

 

@srinidhi 

but you are sending content body so that is not required. this is what I mentioned.

you need to pass those in url parameters

form the URL and include variable substitutions

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

Ok, can you help me with the url and script please.

@srinidhi 

please start from your side

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader