Collection Variables don't stock array

Hi,

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.

Is that a known issue ?

Hey @paullilloesquerre :wave:

Welcome to the Postman Community! :postman:

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

Hello,
I cannot share the exact script.
The context is in a run with newman on Gitlab.

I’m doing a loop on a single request with pm.execution.setNextRequest(SameRequestName) that:

  1. Setup a variable containing my desired Array on the 1st pass
  2. I’m saving it in a variable
  3. I get the saved variable in the next iteration of the loop
  4. If i save it as a collectionVariable - I obtain a string, and when doing a variable[0] I obtain a single character
  5. If I save it as an environmentVariable - I obtain an array, and when doing a variable[0] I obtain a full 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.

You should stringify the array when storing it, and JSON parse it when retrieving it.

I don’t know why it would be different in a collection variable though.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.