# Collection Variables don't stock array

**URL:** <https://community.postman.com/t/collection-variables-dont-stock-array/64090>\
**Category:** Help Hub\
**Tags:** variables, collections\
**Created:** [July 15, 2024, 8:16am UTC](https://community.postman.com/t/collection-variables-dont-stock-array/64090 "2024-07-15T08:16:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![paullilloesquerre](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@paullilloesquerre](https://community.postman.com/u/paullilloesquerre)\
**Post date:** [July 15, 2024, 8:16am UTC](https://community.postman.com/t/collection-variables-dont-stock-array/64090/1 "2024-07-15T08:16:34Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [July 16, 2024, 10:29am UTC](https://community.postman.com/t/collection-variables-dont-stock-array/64090/2 "2024-07-16T10:29:52Z")

</div>

Hey @paullilloesquerre 👋

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. 🤔

---

<div class="post-metadata">

**Author:** ![paullilloesquerre](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@paullilloesquerre](https://community.postman.com/u/paullilloesquerre)\
**Post date:** [July 16, 2024, 12:39pm UTC](https://community.postman.com/t/collection-variables-dont-stock-array/64090/3 "2024-07-16T12:39:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [July 16, 2024, 1:20pm UTC](https://community.postman.com/t/collection-variables-dont-stock-array/64090/4 "2024-07-16T13:20:59Z")

</div>

Are you able to mock out that interaction in a sample Collection using the [https://postman-echo.com/get](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.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [July 16, 2024, 2:48pm UTC](https://community.postman.com/t/collection-variables-dont-stock-array/64090/5 "2024-07-16T14:48:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [August 15, 2024, 2:49pm UTC](https://community.postman.com/t/collection-variables-dont-stock-array/64090/6 "2024-08-15T14:49:11Z")

</div>

Closed on August 15, 2024, 2:49pm UTC

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