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

rickymanuel
Tera Contributor

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.

16 REPLIES 16

Hi A.R.G.  


Here is my script.  I receive an error message

 

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://mycompany.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("MID_SERVER_NAME");
restMessage.setRequestHeader("Authorization", "Bearer " + token);
restMessage.setRequestHeader("Content-Type", "application/json");
restMessage.setRequestBody('{"adjusterId":"318017","bugTicket":"INC999999","updateByUserName":"ricky_manuel@mycompany.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);	

Hi Ricky,

you are setting the mid server name properly; give exact name of the mid server there

also what error message you are getting? can you share it?

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Here is the log I receive from sys_outbound_http_log table

 

 

find_real_file.png

Hi Ricky,

Did you check with the 3rd party Team what does the error mean? any value not sent from your side.

error 400 means bad request so something is not sent properly in your request

Did you get sample request and response body from them so that you can compare

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi Ricky,

Any update on this?
Can you mark my answer as correct, 👍 helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.

Regards
Ankur

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