The Zurich release has arrived! Interested in new features and functionalities? Click here for more

post Rest message script in flow designer

chandan2212
Tera Contributor

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?

 

(function execute(inputs, outputs) {
    var phonenumber = inputs.phonenumber;
    var workphone = inputs.workphone;

    try {
        var r = new sn_ws.RESTMessageV2('rest message''post message');

        // If you're using parameters in the REST message body template
        r.setStringParameterNoEscape('phonenumber', phonenumber);
        r.setStringParameterNoEscape('workphone', workphone);

        // Alternatively, if you're building the body manually:
        // var requestBody = JSON.stringify({
        //     "phonenumber": phonenumber,
        //     "workphone": workphone
        // });
        // r.setRequestBody(requestBody);

        var response = r.execute();
        var responseBody = response.getBody();
        var httpStatus = response.getStatusCode();

        // Optionally log or output the response
        outputs.responseBody = responseBody;
        outputs.httpStatus = httpStatus;
        output.responseBody=responseBody;
    } catch (ex) {
        var message = ex.message;
        outputs.error = message;
    }
})(inputs, outputs);
 
 
whether this script is correct or wrong ?
0 REPLIES 0