Getting the body of an HTTP request from a ServiceNow Outbound REST API.
I cannot seem to get the body of the request correct. The API triggers correctly, but the parameters I am expecting to see (number, short description and state) are coming through as null?
This is my current Business Rule code. - I am using this to trigger a Power Automate flow using the "When an HTTP request is received". The flow triggers, but the body of the request is null when it should contain the number, short description and state values.
(function executeRule(current, previous /*null when async*/) {
// Define HTTP request settings
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('post');
// Define the endpoint URL
request.setEndpoint('my redacted endpoint');
// Set the request body
request.setRequestBody(JSON.stringify({
'number': current.number.toString(),
'short_description': current.short_description.toString(),
'state': current.state.toString()
}));
// Send the HTTP request and get the response
var response = request.execute();
var httpResponseStatus = response.getStatusCode();
var httpResponseContentType = response.getHeader('Content-Type');
var parser;
var obj;
if (httpResponseStatus === 200) {
var responseBody = response.getBody();
parser = new global.JSONParser();
obj = parser.parse(responseBody);
// Log success message
gs.info('HTTP request sent successfully: ' + JSON.stringify(obj));
} else {
// Log error message
gs.error('HTTP request failed with status: ' + httpResponseStatus);
}
})(current, previous);