# Postman:How to resolve Variable not defined error

**URL:** <https://community.postman.com/t/postman-how-to-resolve-variable-not-defined-error/28785>\
**Category:** Help Hub\
**Created:** [October 15, 2021, 8:32pm UTC](https://community.postman.com/t/postman-how-to-resolve-variable-not-defined-error/28785 "2021-10-15T20:32:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayapostmangmail](https://avatars.discourse-cdn.com/v4/letter/j/aca169/32.png) [@jayapostmangmail](https://community.postman.com/u/jayapostmangmail)\
**Post date:** [October 15, 2021, 8:32pm UTC](https://community.postman.com/t/postman-how-to-resolve-variable-not-defined-error/28785/1 "2021-10-15T20:32:18Z")

</div>

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”

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/6/66ad69b0d46d08c9ab4fc7227c8e3028e0ab9b06.png)

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.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [October 16, 2021, 6:20am UTC](https://community.postman.com/t/postman-how-to-resolve-variable-not-defined-error/28785/2 "2021-10-16T06:20:44Z")

</div>

Hey @jayapostmangmail

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

```auto
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/](https://www.chaijs.com/api/bdd/)

---

<div class="post-metadata">

**Author:** ![jayapostmangmail](https://avatars.discourse-cdn.com/v4/letter/j/aca169/32.png) [@jayapostmangmail](https://community.postman.com/u/jayapostmangmail)\
**Post date:** [October 19, 2021, 5:18pm UTC](https://community.postman.com/t/postman-how-to-resolve-variable-not-defined-error/28785/3 "2021-10-19T17:18:26Z")

</div>

> [@danny-dainton](#):
>
> `to.be.`

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.

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/9/9c6cc0d22d20ace7963babd8e42e9e239bf105e3.png)

and this is how I have defined my variable:

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/2/28b575921a29af53b656f1956d0323116737e47a.png)

Could you please help.Thank you

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [October 19, 2021, 7:11pm UTC](https://community.postman.com/t/postman-how-to-resolve-variable-not-defined-error/28785/4 "2021-10-19T19:11:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jayapostmangmail](https://avatars.discourse-cdn.com/v4/letter/j/aca169/32.png) [@jayapostmangmail](https://community.postman.com/u/jayapostmangmail)\
**Post date:** [October 22, 2021, 1:39am UTC](https://community.postman.com/t/postman-how-to-resolve-variable-not-defined-error/28785/5 "2021-10-22T01:39:15Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/3/37e9a94bd3bad40eaa270234a7529dbe5003a4c6.png)
