Hello.
I’ve defined a variable with the exact same name on environment and collection levels.
I would like to see the collection variable value to overlap and prevail in my requests inside the collection, but that’s not working. When I hover the mouse over the variable in the request, it appears Scope= environment. How can I make the collection variable value to prevail over the environment one?
Is I disable the environment one the collection one is working properly.
But I would like to have both enable: the env one for generic collections, and a collection one in cases I need a different value on the scope of that specific collection.
Welcome to the Postman Community!
This might help you understand a little more about the different variable scopes and which ones would take priority:
If a variable with the same name is declared in two different scopes, the value stored in the variable with narrowest scope will be used. For example, if there is a global variable named
username
and a local variable namedusername
, the local value will be used when the request runs.
Hum… Thanks Danny. I’ve read it differently somewhere (env variables being broader than collection ones).
Anyway, taking this new information in consideration, there’s no way I can set some variables at environment level (to be used as ‘default values’) and then just define on collection level when I want them to be different that the env/default ones?
No, as the Environment scope is higher than the Collection Scope.
You could potentially create a pre-request script that reads the collection variable if it exists and then sets a local variable with the same name\value.
If the collection variable doesn’t exist, then the current value in the environment variable should then get used as it will be the only place that the variable is defined in this situation.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.