post Rest message script in flow designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi all ,
I am using a REST message with the POST method in Flow Designer. I am sending two input fields: phonenumber and workphone. I have created the REST message, set the endpoint, and configured basic authentication. Below is the preview script I’m using:
Can anyone confirm whether this script is correct or needs improvement?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago - last edited an hour ago
try something like this
(function execute(inputs, outputs) {
var phonenumber = inputs.phonenumber;
var workphone = inputs.workphone;
try {
var r = new sn_ws.RESTMessageV2('rest message', 'post message');
// Option 1: Using parameters if placeholders exist in REST message body
r.setStringParameterNoEscape('phonenumber', phonenumber);
r.setStringParameterNoEscape('workphone', workphone);
// Option 2: OR build request body directly (if no placeholders)
// var requestBody = JSON.stringify({
// "phonenumber": phonenumber,
// "workphone": workphone
// });
// r.setRequestBody(requestBody);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
outputs.responseBody = responseBody;
outputs.httpStatus = httpStatus;
if (httpStatus !== 200) {
outputs.error = "Unexpected HTTP status: " + httpStatus;
}
} catch (ex) {
outputs.error = ex.message;
}
})(inputs, outputs);