data send to rest post method message using 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('xyz 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);
 
while the script i am receiing the status code :
 
{ "Action Status": { "code": 0, "message": "Success" } }
 
 
I amreceving the three logs :
 
2025-09-26 02:54:35WarningEncountered undeclared output variable: error
2025-09-26 02:54:35WarningEncountered undeclared output variable: httpStatus
2025-09-26 02:54:35WarningEncountered undeclared output variable: responseBody
 
Can you help me how to resolve the problem.
 
 
Thanks and Regards,
Chandan 
 
 
1 ACCEPTED SOLUTION

Missing s in output:

 outputs.responseBody=responseBody;

 

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@chandan2212 

if you are using flow then no scripting required.

you can directly use REST Step and include the body etc

Outbound REST integration using flow designer 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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