24

Currently, it is possible to set and get variables from the global and environment scope, as well as the generic variable in a pre-request script. However, the documentation is not clear if it is possible to programmaticaly set collection scoped variables.

For example

pm.environment.set("timestamp", timestamp);  //acceptable
pm.global.set("signature", hash);  //acceptable
pm.variable.set("signature", hash); //acceptable
pm.collection.set("signature", hash); //not possible?

Is this possible?

dmorrow
  • 5,152
  • 5
  • 20
  • 31
  • Does this answer your question? [Accessing Collection Variables in Postman](https://stackoverflow.com/questions/47680580/accessing-collection-variables-in-postman) – Henke Jan 26 '21 at 17:09

1 Answers1

28

You can only currently set these manually at the Collection level but you can reference these using the pm.variables.get('var_name') syntax.

https://www.getpostman.com/docs/v6/postman/environments_and_globals/variables#defining-collection-variables

EDIT:

Postman now allows you to use:

pm.collectionVariables.set('var_name', 'var_value') and pm.collectionVariables.get('var_name') to interact with the Variables at the Collection level.

https://stackoverflow.com/a/58325002/6028443

Danny Dainton
  • 23,069
  • 6
  • 67
  • 80
  • Programmatically setting the Collection level variables will be part of the app very soon. Should added around `7.9.0` so be on the look out for it. – Danny Dainton Oct 03 '19 at 17:33
  • 4
    For those landing here from Google, `pm.collectionVariables` is what I needed. See the StackOverflow linked in the edit above. At the time of posting this comment, there appears to be little-to-no documentation on the new API. – Jonathan Apodaca Oct 21 '19 at 21:54