But I can’t find instructions on how to add a Collection variable in the app UI. Is this something I can only do via script, such as a pre-request or test script?
Once those are set within that area on the UI, you’re able to use the values in the same way that you would use the other variables.
This doesn’t have a pm.collections.get() type syntax but you can use pm.variables.get("var_name") syntax to programatically access the collection level variable value.
How about setting a collection variable in a pre-request script? I’m reading the docs to try to figure out why I can’t seem to make pm.variables.set() work.
I mean, if I need to set a variable from within a pre-req script, must I use Globals?
Currently, you can only use the .get() function to access the collection level values. You’re not able to use the .set() function within the prerequest/test scripts. Hence the reason why the manual setting of these variables, was offered as the solution.
There is an open issue for that enhancement, over on GitHub.
It took me a while to find the correct “…” menu. There are “…” menus next to the tabs and each “folder” in the collection. The “…” menu you need to find is invisible until the mouse cursor is over the collection’s entry in the left panel. This screenshot shows where to look:
Are there any plans of adding the functionality that allow users to set the variable type (Default or Secret) for Collection Variables? It is not available in the UI as of now.
Also, it would be nice if users could programmatically set the type while creating them through scripts. Currently, I have to manually toggle the type for each variable I wish to hide.