Home > Enterprise >  responseBody is not defined in Postman
responseBody is not defined in Postman

Time:04-15

I have JSON like below:

{
    "success": true,
    "code": 200,
    "message": "Success",
    "data": [
        {
            "ID_A": "AXCS-1-1",
            "ID_B": "AXCS-1-1",
            "Number": "11009988"
        }
    ]
}

And my script for testing in postman:

var data = JSON.parse(responseBody);

if(responseCode.code === 200){
    pm.environment.set("IdA",data.data[0].ID_A);
    pm.environment.set("IdB",data.data[0].ID_B);
}

And I get the response:

How to fix this?

CodePudding user response:

The error says responseBody is not defined and the error is from prerequest script

responseBody is a global object that contains the response , this variable is available only in test script , and as pre-request is executed before the request is even send, requestBody variable wont be accessible

  • Related