Parsing the response body from rest step... help

AbineshM
Tera Contributor
Input response body i am getting from a rest step and response body is a string field. I am getting undefined at the gs.info step and excution goes into ELSE everytime. What am i doing wrong
 
 
(function execute(inputs, outputs) {
    var parsed_response_body =  JSON.parse(inputs.response_body);

 

   
 
    gs.info("Response res1 *****" + parsed_response_body.status + "*****")
 
    if (global.JSUtil.notNil(parsed_response_body.status) && (parsed_response_body.status).contains('ERROR')) {
        outputs.err_code = parsed_response_body.uniqueErrorCode;
        outputs.err_msg = parsed_response_body.message;
        outputs.ret_code = "ERROR";
       
    } else {
        outputs.err_code = 200;
        outputs.err_msg = '';
        outputs.ret_code = "SUCCESS";
    }

 

})(inputs, outputs);
 
Logs:
Response res1 *****undefined*****
1 REPLY 1

Mohan raj
Mega Sage

Hi @AbineshM,

 

I think response is in Object format, try to check what is the typeof inputs.response_body.

if it return string then we need to parse 

if it return object then your no need to parse the inputs.response_body 

 

Try to access the key

 

 

 

var response=  typeof inputs.response_body;
gs.info('check type of variable : ' +response); // if it return string 

gs.info("Response res1 *****" + response.status + "*****")

 

 

If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.

Regards,

T Mohan.