REST API for delete?

Ravish Shetty
Tera Guru

Hello all,

I am using the scriptable REST API to delete some data from a target SN environment

  var r = new RESTMessageScripted("post", "https://"+instanceName+".service-now.com/sys_user_grmember.do");

  r.addHeader("Content-Type", "application/json");

  r.addRequestParameter("JSONv2", "true");

  r.addRequestParameter("sysparm_query", 'sys_id='+id);

  r.addRequestParameter("sysparm_action", "delete");

  r.setBasicAuth(authenticatingUsername, authenticatingPassword);

  response = r.execute();

This doesnt seem to work. The response code that i am getting is 200 so i dont think it is the authentication issue. What am i missing?

1 ACCEPTED SOLUTION

Mike Allen
Mega Sage

var request = new GlideHTTPRequest ('https://myinstance/api/now/table/incident/0fbbeddad47e1100a92e188eafa1dd60');


request.setBasicAuth("admin","admin");


request.addHeader('Accept','application/json');


request.addHeader('Content-Type','application/json');



var response = request.del();



gs.log(response.getStatusCode());


gs.log(response.getBody());


View solution in original post

7 REPLIES 7

I believe yes is the answer to both:



REST: api/now/table/incident


HTTPS: https://myinstance


Hi Mike,



This is a good thing to know. I want to quit using 'RESTMessageScripted' and use this out of the box 'GlideHTTPRequest'.


With GlideHTTPRequest, i can delete, update and insert data.


However there is this one use case where i want to fetch some data by querying it. In the documentation i did not find anything for that.


Here is the code what i use today



var r = new RESTMessageScripted("post", "https://"+instanceName+".service-now.com/sys_user_grmember.do");


r.addHeader("Content-Type", "application/json");


r.addRequestParameter("JSONv2", "true");


r.addRequestParameter("sysparm_query", 'group='+group+'^user='+user);


r.setBasicAuth(authenticatingUsername, authenticatingPassword);


response = r.execute();



var jsonData = new JSON().decode(response.getBody().toString());


if(jsonData.records.length == 0){


return true;


} else {


return false;


}


Hi Ravish,


Yes that is the REST API to handle tables and that's why name is Table API