How do I set a Collection variable?

The documentation says I can have variable on several scopes:


The following scopes are available for use:

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?

1 Like

If you edit the collection ("…" > Edit), you can see a variables tab for it :slight_smile:


Thank you very much!

Just to add some additional information here:

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.

1 Like

Thank you, @dannydainton.

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. :grin:

There is an open issue for that enhancement, over on GitHub. :grin:


Can this be done through the web interface as well? If so, how? Thank you.