How to call a DELETE method

SNOW39
Tera Expert

We have a delete method API which has parameters from variable.How to trigger it form script incude and get the status from workflow.

8 REPLIES 8

ID and number is variable in the catalog form we have created. The delete operation happens in the system where we are calling the API. 

When are you calling the rest api given in the try-catch block?........... In the workflow defined for the item

Hi,

so you are trying to delete catalog variable?

the table which stores that is "item_option_new"

Can you share more details on this what exactly is required?

Also DELETE endpoint requires table name and record sys_id to delete

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

Regards
Ankur

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

Megha Padale
Giga Guru

Hi,

Check this sample code.

try {
	var userID = "testUserID";
	var requestBody = {
		"userId": 0,
		"bugTicket": "string",
		"updateByUserName": "string"
	};
	var r = new sn_ws.RESTMessageV2();
	r.setEndpoint('https://userapi-company_name.net/api/support/user/adjuster/'+userID);
	r.setHttpMethod('DELETE');
	r.setMIDServer('MY_MID_SERVER');
	r.setRequestBody(requestBody);//Strigfy it if it doesnt work
	var response = r.execute();
	var responseBody = response.getBody();
	var httpStatus = response.getStatusCode();
	gs.log("Recieved response from 3rd party "+httpStatus+" | "+responseBody);
}
catch(ex) {
	var message = ex.message;
}

If my answer helped you in any way, mark answer as helpful and correct.

Thanks and regards,

Megha.

We dont have a request body, the URL has the parameters