# How to pass a variable with a collection using Newman library

**URL:** <https://community.postman.com/t/how-to-pass-a-variable-with-a-collection-using-newman-library/23144>\
**Category:** Help Hub\
**Tags:** newman-project, variables, collections\
**Created:** [April 27, 2021, 10:00am UTC](https://community.postman.com/t/how-to-pass-a-variable-with-a-collection-using-newman-library/23144 "2021-04-27T10:00:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unslog](https://avatars.discourse-cdn.com/v4/letter/u/a9adbd/32.png) [@unslog](https://community.postman.com/u/unslog)\
**Post date:** [April 27, 2021, 10:00am UTC](https://community.postman.com/t/how-to-pass-a-variable-with-a-collection-using-newman-library/23144/1 "2021-04-27T10:00:11Z")

</div>

> **Archived topic — this may be out of date.**  
> Newman has been replaced by the **[Postman CLI](https://learning.postman.com/docs/postman-cli/postman-cli-overview/)**, Postman’s official, signed command-line tool. It runs collections as Newman did, and also lints API specs, runs mocks and monitors, and syncs local files with Postman from your terminal, CI/CD pipeline or coding agent.  
> Working with an AI coding agent? The [Postman plugin](https://github.com/postmanlabs/postman-plugin) lets agents in Claude Code, Cursor, Codex and others design, mock, test and ship APIs with Postman.  
> For current help, see the [Postman docs](https://learning.postman.com/docs/), try the free [Postman tools](https://www.postman.com/tools) (no account needed), or join us on [Discord](https://discord.gg/58aNNsRBGR).

Hi everyone,

I’m new to the world of node.js / newman so please bear with me 🙂

I used this excellent Youtube clip [How to programmatically save the response to file in Postman - YouTube](https://www.youtube.com/watch?v=cCRmry10874) to help me build a script to automate posting of data to supplier and write the response to a file.

In essence, I’m trying to build a script that loops through XML files stored in a windows directory and posts the contents of the XML file to the supplier’s HTTP API using Newman.

The issue; how do I pass the content from the XML to the “collection:require statement” , just unsure of the syntax.

 ![2021-04-27 10_42_35](https://us1.discourse-cdn.com/getpostman/original/3X/0/d/0d174e787bb152da43b8835193398636a9595025.png)

I already have a variable in the collection to hold the API “body” as per screenshot;

![](https://i.stack.imgur.com/uGBYU.png)

Hope this makes sense

Thanks

---

<div class="post-metadata">

**Author:** ![unslog](https://avatars.discourse-cdn.com/v4/letter/u/a9adbd/32.png) [@unslog](https://community.postman.com/u/unslog)\
**Post date:** [April 28, 2021, 8:24am UTC](https://community.postman.com/t/how-to-pass-a-variable-with-a-collection-using-newman-library/23144/2 "2021-04-28T08:24:49Z")

</div>

I think I got this working, using this post - [node.js - How can a Postman environment variable value be passed into an nodejs script executing Newman? - Stack Overflow](https://stackoverflow.com/questions/60381606/how-can-a-postman-environment-variable-value-be-passed-into-an-nodejs-script-exe)

Define the environmentVariables , in my case data is a variable that contains content from the XML file

```
environmentVariables = [];
environmentVariables.push(
  {
      key: "testBody",
      value: data,                    
  }
   );

```

Pass the variable to the collection run

```
newman.run ({
      collection: require('c:/postman/postman_collection.json'),
      envVar: environmentVariables,
      reporters: 'cli'
```
