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.
Please anyone tell me How to fix that issue.
Thank You
@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:
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
@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.
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.
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
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))
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?
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
Now, my issue is resolved, I selected the differerent environment for my monitors that’s it was showing an error.
Thanks @praveendvd @bpricilla