Postman:How to resolve Variable not defined error

Fairly new to automating API tests in postman: I am trying to fetch a environment variable for my assertion- And I keep getting this error “Validating the output | ReferenceError: PartC is not defined”

From different posts , I am thinking there is a data type mismatch but how do I find the data type of my JSON response and fix it? any help.

Hey @jayapostmangmail

The correct syntax for .get is to wrap the variable name in quotes.

pm.environment.get("var_name");

This isn’t quite right on line 13. The error is more than likely coming from line 14, when it tries to log the undefined variable.

The expect statement doesnt look quite right either, to.be.a() would be “string”, “number”, “array”, “object” etc.

More info on those assertions can be found here:

https://www.chaijs.com/api/bdd/

1 Like

Thank you , That helps- I have modified the syntax and don’t see the undefined error anymore. see the following error now, I tried using parseInt seeing your other post.

and this is how I have defined my variable:

Could you please help.Thank you

The to.be.a are all failing on those other lines as it doesn’t expect that value.

Thank you very much @danny-dainton you are correct- Those lines were causing the error. Could you please also tell me what is the syntax for _.sum function and how it works. In my above screen I am trying to add PartC and PartD variables. I tried the parseInt for each variable within the _.sum that dint work.