Has anyone used the REST "DELETE' method for outbound REST Messaging?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2019 06:46 AM
The field 'Content' was not visible on the form but I updated the UI Policy to show the content so i can use the JSON body. However, when I tried to test my DELETE method and hardcoding the values on my JSON body I get an error:
{"errors":{"":["A non-empty request body is required."]},"title":"One or more validation errors occurred.","status":400,"traceId":"|f7ba0e33b142d84a91d2e7f57a7cafb5.40b1f8fb_"}.
If I run my DELETE in Postman it works.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2019 08:22 AM
Hi Ricky,
Did you replace the adjusterId with the actual value in the endpoint while testing?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2019 08:28 AM
Yes I did
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2019 08:44 AM
Hi Ricky,
there is something missing when you do it from ServiceNow
Did you compare the difference between Postman and ServiceNow?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2019 11:03 AM
Ricky,
I understand you edited the UI policy to force the page to intake the requestbody. But who knows whats running in the background in the OOB ServiceNow functionality. To test this, I suggest you to run the code directly in the Background script or Fix script. Because end of the day, your OutBound Rest API configuration needs to be utiliized via code, so why not change the code a bit like below. Tweak the below code according to your needs.
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;
}
Hope this helps.
Thank you,
A.R.G.
Please mark the answer as helpful/correct if applicable!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2019 07:24 AM
Thank you A.R.G! This is my script that I am using:
var r = new sn_ws.RESTMessageV2('Polaris', 'retrieveOauthToken');
var response = r.execute();
var responseBody = response.getBody();
var parseBody = JSON.parse(responseBody)
var httpStatus = response.getStatusCode();
var token = parseBody.access_token;
gs.info("AccessToken:" + token);
var url = "https://mydomain.net/api/support/user/adjuster/";
var adjusterId = "318017";
var endPnt = url + adjusterId;
var restMessage = new sn_ws.RESTMessageV2();
restMessage.setHttpMethod("delete");
restMessage.setEndpoint(endPnt);
restMessage.setMIDServer("AZ1-D-SNOW001");
restMessage.setRequestHeader("Authorization", "Bearer " + token);
restMessage.setRequestHeader("Content-Type", "application/json");
restMessage.setRequestBody('{"adjusterId":"318017","bugTicket":"INC999999","updateByUserName":"ricky_manuel@mydomain.net"}');
// Execute REST API Call
var response1 = restMessage.execute();
response1.waitForResponse(60);
var resBody = response1.getBody();
var parseBody1 = JSON.stringify(resBody);
var httpStatus1 = response1.getStatusCode();
var str_code = '';
if (httpStatus1 > '199' && httpStatus1 < '301'){
str_code = 'Complete - '+ httpStatus1 + '\n'+'\n';
str_code = str_code + ' ' + parseBody1 + '\n';
} else {
str_code = 'Complete but Not Successful - '+ httpStatus1 + '\n'+'\n';
str_code = str_code + ' ' + parseBody1 + '\n';
// str_code = str_code + 'Bug Ticket: ' + bugTicket;
}
gs.print(str_code);