# ReferenceError: BasketID is not defined

**URL:** <https://community.postman.com/t/referenceerror-basketid-is-not-defined/67875>\
**Category:** Help Hub\
**Tags:** tests, variables\
**Created:** [September 3, 2024, 8:27am UTC](https://community.postman.com/t/referenceerror-basketid-is-not-defined/67875 "2024-09-03T08:27:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![arshedahmed](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@arshedahmed](https://community.postman.com/u/arshedahmed)\
**Post date:** [September 3, 2024, 8:27am UTC](https://community.postman.com/t/referenceerror-basketid-is-not-defined/67875/1 "2024-09-03T08:27:00Z")

</div>

Hi,

I am getting error “ReferenceError: BasketID is not defined”. I have created a Global Variable call “BasketID”. and during my test I am storing value from response against the variable.

After running script I can see the Global Variable is showing value, but in console I get the error. I am new to Postman and struggling to figure this out.

Thanks in advance..

**=== Script=== Post Response ====**  
const response = pm.response.json();  
const basketid = response[“basketId”];

pm.globals.set(“ **BasketID** ”,basketid);

console.log(BasketID);

pm.test("Basket Id is create ", function (){  
pm.expect(pm.response[“basketId”]).to.not.be.null;  
});

pm.test(“Successful POST request”, function () {  
pm.expect(pm.response.code).to.be.oneOf([200,400]);  
});

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/d/e/de4e811736057ca52b4f448b662ca9fc5cdf6353.png)

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/8/a/8a35be76b653a17fee5c245ee2fe0e3842408373.png)

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [September 3, 2024, 9:30am UTC](https://community.postman.com/t/referenceerror-basketid-is-not-defined/67875/2 "2024-09-03T09:30:01Z")

</div>

Hi @arshedahmed. Welcome to the Postman Community!

From the screenshot you shared, you declared a variable “basketid” on line 4, but you’re referencing a variable “BasketID” on line 7. The variables withing your script are local to your script and Global, Collections, and Environments variable cannot be accessed the same way you would access them.

To log a global variable to the console, you will need to modify line 7 to `console.log(pm.globals.get("BasketID"))`

---

<div class="post-metadata">

**Author:** ![arshedahmed](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@arshedahmed](https://community.postman.com/u/arshedahmed)\
**Post date:** [September 3, 2024, 11:51am UTC](https://community.postman.com/t/referenceerror-basketid-is-not-defined/67875/3 "2024-09-03T11:51:38Z")

</div>

works fine… Thank you for your help

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [September 6, 2024, 11:52am UTC](https://community.postman.com/t/referenceerror-basketid-is-not-defined/67875/4 "2024-09-06T11:52:20Z")

</div>

Closed on September 6, 2024, 11:52am UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
