Saving (collection level) variables to fork of a Postman public collection?


I am poking around at the Postman public collections here. In the Environment Scanner collection - the first call saves some data to collection level variables, but they don’t actually seem to persist for me.

I made a fork of the collection, and have the needed environments forked as well.

What I am seeing is this - the first call “Get all workspaces” saves data to collection level variables, but once the call is done, they’re not really saved. I cannot see them. But on the Test tab, I can add this and see it supposedly there, while it is executing.

pm.environment.set("teamWorkspaceArray", teamWorkspaceArr);
console.log(pm.environment.get("teamWorkspaceArray"));  //added, there but not really saved

When I try to run the next call “Access the contents of workspaces accessible to you” the collection variable cannot be read, so that call fails.

If I change the variable to be saved to an environment instead of the collection, the save is persisted. But it doesn’t make sense for me to edit this collection and functionality to just test it. I am guessing that I must be doing something wrong. Please help.


p.s. - I also tried to Export the collection, then import it as a copy, same.

Hi @jonsworkalias :wave:,

That request which you are mentioning is picking only the Team Workspaces.

Make sure you have a Team workspace added for that account :blush:

If you edit the scripts as needed, else you can try exploring other Postman API requests based on your needs :partying_face:

Hi Thanks for the suggestion, but I don’t think that’s it. Here are some screenshots showing what I mean.

Run call and get team data…

Console logs both the variable and collection’s data (these are team workspaces)

But if I then look at the collection’s variables there is nothing there.

So I guess my question (forget about forks etc) - if a Collection Variable is set - should it show up on this page - the page that shows up when I click on the top level folder of a Collection and then the Variable tab?

@jonsworkalias so you used the existing script and no changes right?

Can you share what’s there as part of the “Tests” section?

Because this collection as default had no variables. As per the script,

pm.variables.set("teamWorkspaceArray", teamWorkspaceArr);

is just for local reference and will not assign any collection/environment level variables.

Please try this to know more about the scope of variables.

If you need that as environment variable,

pm.environment.set("teamWorkspaceArray", teamWorkspaceArr);

And Syntax for collection variable is,

pm.collectionVariables.set("teamWorkspaceArray", teamWorkspaceArr);

If you are facing issues, please provide the snippets which you have as part of “Tests” section :blush:

Ah ha! Ok so I misread that on my end for sure. Thanks. I confused variable.set w/ CollectionVariable.set - I don’t normally use either one.

Thanks for taking the time to help me figure out where I went wrong.

1 Like