During recent uses of collections and a misuse of environment variables I decided to work more with collection variables.
Previously, I saved all my variables into those for the environment. But we decided to change that:
*Environment variables will concern only URLs and other settings that may affect the runs in an environment.
*Collection variables will take all the other variables.
With that intent, we tried to save an array into the Collection Variables like we did with the Environment Variables. But we found out that the object when getting the variables from the collection was a string instead of an array.
All set and gets were done in the same way: pm.collectionVariables.set("variable1","value") and pm.collectionVariables.get("variable1") on one side and pm.environment.set("variable2","variable") and pm.evironment.get("variable2") on the other side.
Would you be able to share the exact script that you’re using to set the variables please? It will be easier for use to so what’s happening here.
Are these part of an automation suite or are you running these as individual requests?
From what the have shared so far:
pm.collectionVariables.set("variable1","value")
That would store a string value of value against the variable1 variable. I’m not really seeing how that would be an array or anything other than a string.
Are you able to mock out that interaction in a sample Collection using the https://postman-echo.com/get endpoint and a dummy script.
Your second response contained my context about your workflow, than your original question and without a working example it’s going to difficult to see the full sequence from end to end. There could be certain specific things included in your script that we won’t be aware of.
Using Collection to get and set data during automated runs or one done outside of the Postman UI has caused problems in the past.