How to use a single array object as a data input to collection file with multiple API triggering

I can only re-iterate that Newman mirrors the functionality of the Collection Runner to a certain extent, so try and get it running in the Collection Runner first.

Newman has a lot of command line options, including adding a csv file, or environment file, or just sending what should be contained in variable through the pipeline.

When posting code, JSON, examples responses, please use the preformatted text option in this editor, as its stops all of the code being aligned to the left, which is practically impossible to read without reformatting it.

Think about the Collection as being a Test Suite, the folders being a Test Case, and the requests being the Test Steps.

Therefore you can have the two different API requests in separate folders.

There are options for how to get to the test data, but it depends on how you want to use the data.

It looks like you have three elements in the first set of test data, so are you expecting these request to loop, and the second test of test data has 7, so same question, are you wanting to loop through that? You canโ€™t achieve that with the collection runner alone. You will need code to control the loop.

The way I would deal with the test data is to setup the JSON file, and then minify it, and then send it in the Newman command line so it gets stored in a Postman environment variable. This means you need to include the environment in the Newman command line as well as the collection JSON as well as the option for the variable.

Why a Environment Variable instead of collection? With Environment variables, you can set them as โ€œsecretโ€ which means the value does not get included when you export the file or get copied to the Postman cloud. If the test data is not confidential, then by all means use the Collection Variable. If the test data is not confidential, then you could just include the test data in the variable and save it to your code repository. Not something I recommend unless the test data is static and never changes.

So your test data is now available to your Collection. Now what?

If you are just running each API once, you just need a pre-request script to parse the environment variable and set new variables for each element you are going to parameterise in your test.

When you fetch the variable which will need to be parsed as it will be stored as a string, you would just parse the array that contains the test data for each specific test. Therefore you should be able to have all of the test data in one file, as long as the first element is the test case name. The test data needs to be an array.

If you are going to loop through the test data, then you will still need to parse the data in the pre-request script, but you are going to need to use a concept called array.shift() which takes the first record from the test data array and save it as a variable, and then removes it from the array. You then have to keep saving the new array and current variable so they can be used in the current request. In the Tests tab, you retrieve the updated request and keep looping using setNextRequest while the array length is less than zero.

Hereโ€™s a couple of examples of using array.shift() in different ways.

Loop through values from GET to next PUT request - Help - Postman

Postman delete multiple resource IDs - Help - Postman

Post Looping through an Array not working - Help - Postman

Remember to stringify arrays when storing them as variables, and JSON.parse when retrieving.