# Response code fails only when test runs in browser's monitor

**URL:** <https://community.postman.com/t/response-code-fails-only-when-test-runs-in-browsers-monitor/19136>\
**Category:** Help Hub\
**Tags:** monitors, tests, authentication, json\
**Created:** [January 13, 2021, 8:11pm UTC](https://community.postman.com/t/response-code-fails-only-when-test-runs-in-browsers-monitor/19136 "2021-01-13T20:11:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![billybolton](https://avatars.discourse-cdn.com/v4/letter/b/f14d63/32.png) [@billybolton](https://community.postman.com/u/billybolton)\
**Post date:** [January 13, 2021, 8:11pm UTC](https://community.postman.com/t/response-code-fails-only-when-test-runs-in-browsers-monitor/19136/1 "2021-01-13T20:11:36Z")

</div>

Hi there,

I am currently testing the responses codes for various api requests. These tests all run as expected within the Postman Desktop app when ran by themselves, when ran through a monitor on the desktop, and when these tests are ran through the on the browser (with the Postman Desktop Agent).

When running these tests through the browser and a monitor however, all of these test cases fail. I also run a test that calls a simple website and this one passes but not the api calls. I double checked that the monitor is running with the proper environment for the api keys.

Has anyone come across this before? I’d like to test what that the environment’s current value for the api key is being sent _when the monitor runs_ but I’m not sure how to do this. I’m confused why these calls work except for in the monitor _through the browser_, and I’m not sure what’s different.

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [January 14, 2021, 12:26am UTC](https://community.postman.com/t/response-code-fails-only-when-test-runs-in-browsers-monitor/19136/2 "2021-01-14T00:26:18Z")

</div>

Hi @billybolton! Welcome to the community 👋

I understand your tests fail only when you run the collection with Postman Monitor, is that correct?

As Postman Monitor is being executed on the Postman server, there are a few differences to be noted, compared to when you run collections locally - please refer to the thread below for more information.

> [@Monitoring Authorization Error](https://community.postman.com/t/monitoring-authorization-error/18761/3):
>
> Hi @jbalasi! I understand you are using a API key that is set as a global variable when running a monitor, correct? Monitor does not have access to global variables so use collection/environment variables instead. FYI, a few differences between runner and monitor: All API must be publicly available No access to global variables (use collection/environment variables instead) No access to CURRENT VALUE (remember CURRENT VALUE is local to your session) Hope this helps!

Having said that, in your current situation, I wonder if your api keys are stored in CURRENT VALUES of environment - if so, please copy them to INITIAL VALUES so that those values are accessible by the Monitor.

You also mentioned you would like to check the value used for api keys - for this, you can simply include `console.log()` in Test scripts. This will then printed out in the **console log** tab of your Monitor page.

 ![support-image](https://us1.discourse-cdn.com/getpostman/original/3X/f/0/f0d369333de37b292b4c40cb18d43c2b8321db0d.png)

Hope this helps! Please let me know if you have further questions 🙂

---

<div class="post-metadata">

**Author:** ![thefierycoder](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@thefierycoder](https://community.postman.com/u/thefierycoder)\
**Post date:** [January 14, 2021, 10:28am UTC](https://community.postman.com/t/response-code-fails-only-when-test-runs-in-browsers-monitor/19136/3 "2021-01-14T10:28:39Z")

</div>

Hello @taehoshino ,  
I am also facing the same error.  
After applying your tips, I am still getting an unauthorised error but when I replace environment variable with my api key value then it works fine.  
And when I do `console.log(pm.environment.get('airtable_api_key'));` in the test script, it returns undefined.  
Please help me with this.

 ![Screenshot from 2021-01-14 15-05-02](https://us1.discourse-cdn.com/getpostman/original/3X/5/f/5f2aef581ad9ce763644a5dfcc9d32ed4a735781.png)

---

<div class="post-metadata">

**Author:** ![billybolton](https://avatars.discourse-cdn.com/v4/letter/b/f14d63/32.png) [@billybolton](https://community.postman.com/u/billybolton)\
**Post date:** [January 14, 2021, 12:56pm UTC](https://community.postman.com/t/response-code-fails-only-when-test-runs-in-browsers-monitor/19136/4 "2021-01-14T12:56:41Z")

</div>

Hi there @taeshoshino, thank you for getting back to me so quickly!

This is a great response. Unfortunately, I’m working with confidential APIs and cannot expose these keys as initial values to the network directly for security reasons. Is there another way to do this without exposing this information?

---

<div class="post-metadata">

**Author:** ![billybolton](https://avatars.discourse-cdn.com/v4/letter/b/f14d63/32.png) [@billybolton](https://community.postman.com/u/billybolton)\
**Post date:** [January 14, 2021, 3:31pm UTC](https://community.postman.com/t/response-code-fails-only-when-test-runs-in-browsers-monitor/19136/5 "2021-01-14T15:31:37Z")

</div>

With more investigation, it seems that encrypting secrets is not a feature Postman supports: [Feature Request: Secure variable option · Issue #6639 · postmanlabs/postman-app-support · GitHub](https://github.com/postmanlabs/postman-app-support/issues/6639)

Although not ideal, I have access to the backing API that has allowed me to test response codes successfully, so this is a work around if others have access to those backing APIs as well. You don’t need an API key to do this. I’m not sure this is a solution that can serve most users, however.

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [January 15, 2021, 12:49am UTC](https://community.postman.com/t/response-code-fails-only-when-test-runs-in-browsers-monitor/19136/6 "2021-01-15T00:49:20Z")

</div>

Thanks for getting back @billybolton!

Glad to hear you have found a workaround - I understand it would be ideal to have a secure variable option as described in the GitHub issue.

You are encouraged to leave your comment in the issue to weigh in! Our product managers use that feedback to prioritize and add items to our development roadmap 😃

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [January 15, 2021, 12:56am UTC](https://community.postman.com/t/response-code-fails-only-when-test-runs-in-browsers-monitor/19136/7 "2021-01-15T00:56:24Z")

</div>

Hi @thefierycoder 👋

I understand you are seeing the same issue when running collections using Monitor.

> And when I do `console.log(pm.environment.get('airtable_api_key'));` in the test script, it returns undefined.

This suggests that the correct environment may not be selected for the monitor - please go to your web dashboard and check the monitor setting (as below).

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

Hope this helps! Please feel free to reach out if you have further questions 🙂

---

<div class="post-metadata">

**Author:** ![thefierycoder](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@thefierycoder](https://community.postman.com/u/thefierycoder)\
**Post date:** [January 15, 2021, 5:33am UTC](https://community.postman.com/t/response-code-fails-only-when-test-runs-in-browsers-monitor/19136/8 "2021-01-15T05:33:37Z")

</div>

You’re right I selected the different environment.  
Thanks

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [January 15, 2021, 5:35am UTC](https://community.postman.com/t/response-code-fails-only-when-test-runs-in-browsers-monitor/19136/9 "2021-01-15T05:35:30Z")

</div>

Happy to help! @thefierycoder

Please feel free to reach out if you have any other questions 😉

---

<div class="post-metadata">

**Author:** ![navairabari16](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@navairabari16](https://community.postman.com/u/navairabari16)\
**Post date:** [September 30, 2021, 9:18am UTC](https://community.postman.com/t/response-code-fails-only-when-test-runs-in-browsers-monitor/19136/10 "2021-09-30T09:18:18Z")

</div>

Hi,  
I am having the same issue that "These tests all run as expected within the Postman separately, but when I ran using Monitor, I am receiving the error 404 Not Found. I have tried the tip that is mentioned here in a comment, that says “copy paste the Current Value to Initial Value”, but even then I am facing the Test Failed issue, also I am . I am also sharing the screenshot.

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

---

<div class="post-metadata">

**Author:** ![maintenance-archite1](https://avatars.discourse-cdn.com/v4/letter/m/f4b2a3/32.png) [@maintenance-archite1](https://community.postman.com/u/maintenance-archite1)\
**Post date:** [June 16, 2023, 3:06pm UTC](https://community.postman.com/t/response-code-fails-only-when-test-runs-in-browsers-monitor/19136/11 "2023-06-16T15:06:25Z")

</div>

This helped. Thank you very much.
