# Monitor doesn't recognize api keys

**URL:** <https://community.postman.com/t/monitor-doesnt-recognize-api-keys/19151>\
**Category:** Help Hub\
**Tags:** monitors, collections, authentication\
**Created:** [January 14, 2021, 8:22am UTC](https://community.postman.com/t/monitor-doesnt-recognize-api-keys/19151 "2021-01-14T08:22:19Z")\
**Posts on this page:** 9\
**Page:** 1

<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, 8:22am UTC](https://community.postman.com/t/monitor-doesnt-recognize-api-keys/19151/1 "2021-01-14T08:22:19Z")

</div>

Hello Everyone,  
When I try to run collection using monitor, it returned an unauthorized user error like this `expected response to have status code 200 but got 401`, it doesn’t recognizes my api keys when I run collection using monitors. But when I run that collection using collection runner from the postman app, It works fine.  
I saved my key using environment variables and I selected the right environment for monitor to run.  
I am using airtable api.  
 ![Screenshot from 2021-01-14 13-53-30](https://us1.discourse-cdn.com/getpostman/original/3X/3/4/34edf45d48da81b2ae294cfaa88c89aada288d7d.png)  
Please anyone tell me How to fix that issue.  
Thank You

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [January 14, 2021, 9:00am UTC](https://community.postman.com/t/monitor-doesnt-recognize-api-keys/19151/2 "2021-01-14T09:00:25Z")

</div>

@thefierycoder Welcome to the community 💐

This is a commonly asked question in the community, and I suggest you to kindly read the below similar query answered:

> [@Response code fails only when test runs in browser's monitor](https://community.postman.com/t/response-code-fails-only-when-test-runs-in-browsers-monitor/19136):
>
> 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 che…

---

<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, 9:32am UTC](https://community.postman.com/t/monitor-doesnt-recognize-api-keys/19151/3 "2021-01-14T09:32:00Z")

</div>

Hello @bpricilla,  
Thanks for your response.  
Now, I saved my api key inside the initial value but still I am getting unauthorised error when I run the collection using postman monitor. And when I put my api key directly then it works fine.  
And when I do console.log(airtable\_api\_key), it returns undefined.  
I don’t know why I am getting an error

 ![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:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [January 14, 2021, 10:36am UTC](https://community.postman.com/t/monitor-doesnt-recognize-api-keys/19151/4 "2021-01-14T10:36:28Z")

</div>

@thefierycoder oh sorry to hear that! So you are variable scope is not global right? Since Monitors couldn’t access them. It should be either on collection or environment level.

Also please check if your API is publicly available.

---

<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, 11:11am UTC](https://community.postman.com/t/monitor-doesnt-recognize-api-keys/19151/5 "2021-01-14T11:11:12Z")

</div>

I don’t know how to convert an environment variable to global environment variable.  
What I did is I created an Environment inside my workspace and then store my api key as an environment variable over there and set the value of my api key to initial and current value both.  
Now, when I tried to access them using monitor, it didn’t able to access them.

> [@bpricilla](#):
>
> Also please check if your API is publicly available.

When I put my api key value directly, then monitor didn’t show any error.  
It means api is publicly available.  
I am using airtable api.  
If I am wrong, please tell me what do you meant by publicly available api?  
Thank You

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [January 14, 2021, 12:23pm UTC](https://community.postman.com/t/monitor-doesnt-recognize-api-keys/19151/6 "2021-01-14T12:23:04Z")

</div>

Publicly available means it’s authorized to be accessed from outside of your organization

Postman monitor is ran in postman cloud so , it should be authroized and accessible from outside world .

you should create environment variable : airtable\_api\_key ( which you already have )

to print it you should use` console.log(pm.environment.get(airtable_api_key))`

---

<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, 2:18pm UTC](https://community.postman.com/t/monitor-doesnt-recognize-api-keys/19151/7 "2021-01-14T14:18:32Z")

</div>

I am still having the same problem, it’s not recoginizing my airtable\_api\_key.  
I think airtable api is publically available and anyone can use it.  
Everything works fine if I put the keys directly instead of adding through env.  
Do you have any ideas on how to fix that?

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [January 14, 2021, 2:44pm UTC](https://community.postman.com/t/monitor-doesnt-recognize-api-keys/19151/8 "2021-01-14T14:44:32Z")

</div>

Are you using datadriven testing ?

Remove all variables with the same name from local variable (variables set as pm.variables.set() from script ) , and any column in csv or json file used in data driven

As local and data variables have more precedence, value from this will reflect and override env variable value

---

<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/monitor-doesnt-recognize-api-keys/19151/9 "2021-01-15T05:33:03Z")

</div>

Now, my issue is resolved, I selected the differerent environment for my monitors that’s it was showing an error.  
Thanks @praveendvd @bpricilla
