How to pass a variable with a collection using Newman library

Hi everyone,

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

I used this excellent Youtube clip How to programmatically save the response to file in Postman - YouTube 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.

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

Hope this makes sense

Thanks

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

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'