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

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.

Hi @billybolton! Welcome to the community :wave:

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.

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.

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

1 Like

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.

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?

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

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.

1 Like

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 :smiley:

Hi @thefierycoder :wave:

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).

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

You’re right I selected the different environment.
Thanks

1 Like

Happy to help! @thefierycoder

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

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.

This helped. Thank you very much.