# Using '--export-collection' does not output updated collection variables

**URL:** <https://community.postman.com/t/using-export-collection-does-not-output-updated-collection-variables/21777>\
**Category:** Help Hub\
**Created:** [March 24, 2021, 9:10am UTC](https://community.postman.com/t/using-export-collection-does-not-output-updated-collection-variables/21777 "2021-03-24T09:10:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgard1981](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@dgard1981](https://community.postman.com/u/dgard1981)\
**Post date:** [March 24, 2021, 9:10am UTC](https://community.postman.com/t/using-export-collection-does-not-output-updated-collection-variables/21777/1 "2021-03-24T09:10:47Z")

</div>

When using the `newman` CLI (version 5.2.2), there is a requirement to save updated **collection variables** after a run. To achieve this, `-export-collection <path>` is being used but variables in the collection at `<path>` do not contain updated values after a run.

To set a variable value during the run, `pm.collectionVariables.set()` is being used in a request test.

```auto
let jsonResponse = pm.response.json();
pm.collectionVariables.set("myVariable", jsonResponse.value);

```

When testing the request in Postman, the updated variable value persists in the collection. The same is true if the runner is used with **Keep variable values** checked.

However, when using the `newman` CLI the collection variables are not updated after the run.

```auto
newman run collection.json --environment environment.json --export-collection collection.json

```

According to the [documentation](https://www.npmjs.com/package/newman#newman-run-collection-file-source-options), `--export-collection|globals|environment <path>` is -

> The path to the file where Newman will output the final collection / global variables / environment variables file before completing a run.

Testing shows that setting a global/environment variable in the request and using `--export-globals|environment <path>` works, with the output file containing the updated variable value.

Is this a bug with the `newman` CLI, or is there something that can be done to fix this behaviour?

Thanks,  
David

* * *

This question is also on [Stack Overflow](https://stackoverflow.com/questions/66767667/newman-cli-export-collection-not-outputting-updated-collection-variables).

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [March 25, 2021, 1:58am UTC](https://community.postman.com/t/using-export-collection-does-not-output-updated-collection-variables/21777/2 "2021-03-25T01:58:16Z")

</div>

Hey @dgard1981 👋 Welcome to the Postman Community 🎉

Thanks for reporting this. I was able to reproduce the behaviour where the exported collection variables are not updated.

I am currently checking with our internal team if this is an expected behaviour.  
I will let you know once I find out more 😃

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [March 25, 2021, 2:30am UTC](https://community.postman.com/t/using-export-collection-does-not-output-updated-collection-variables/21777/3 "2021-03-25T02:30:08Z")

</div>

Hey @dgard1981,

We now have an open GitHub issue filed here:

> <https://github.com/postmanlabs/newman/issues/2680>
>
> Refer: https://community.postman.com/t/using-export-collection-does-not-output-updated-collection-variables/21777

Please feel free to subscribe to it or add your comments so that you will receive updates 😃

---

<div class="post-metadata">

**Author:** ![dgard1981](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@dgard1981](https://community.postman.com/u/dgard1981)\
**Post date:** [March 25, 2021, 9:16am UTC](https://community.postman.com/t/using-export-collection-does-not-output-updated-collection-variables/21777/4 "2021-03-25T09:16:28Z")

</div>

Thanks @taehoshino, hopefully this is an easy one to resolve in an upcoming release.

Thanks,  
David
