# Newman multiple data files

**URL:** <https://community.postman.com/t/newman-multiple-data-files/17541>\
**Category:** Help Hub\
**Created:** [November 10, 2020, 3:15am UTC](https://community.postman.com/t/newman-multiple-data-files/17541 "2020-11-10T03:15:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![sfreewave](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@sfreewave](https://community.postman.com/u/sfreewave)\
**Post date:** [November 10, 2020, 3:15am UTC](https://community.postman.com/t/newman-multiple-data-files/17541/1 "2020-11-10T03:15:42Z")

</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,  
Is it possible to pass multiple data files via newman. Example call:  
newman run collection.json -e environment.json -d testfile.json -d code.json

Please note collection file needs inputs from both data files- testfile.json and code.json for each run.

---

<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:** [November 10, 2020, 3:40am UTC](https://community.postman.com/t/newman-multiple-data-files/17541/2 "2020-11-10T03:40:23Z")

</div>

Hey @sfreewave

Welcome to the community!

You can only use 1 data file in the Newman run command. What’s your use case for needing 2 files?

---

<div class="post-metadata">

**Author:** ![sfreewave](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@sfreewave](https://community.postman.com/u/sfreewave)\
**Post date:** [November 10, 2020, 4:36am UTC](https://community.postman.com/t/newman-multiple-data-files/17541/3 "2020-11-10T04:36:31Z")

</div>

Hi Danny,  
Thanks for your response. We are using cypress on runtime to generate Auth Code, which store it in file ‘code…json’. And other file ‘testfile.json’ we have to use to provide test data to our collection.

Hence looking for a way how can we run them via newman.

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [November 10, 2020, 7:16am UTC](https://community.postman.com/t/newman-multiple-data-files/17541/4 "2020-11-10T07:16:31Z")

</div>

@sfreewave: Welcome to the Community Swetha 👋

Kindly check this related post:

> [@How to run multiple API request with multiple testdata for each request via Newman](https://community.postman.com/t/how-to-run-multiple-api-request-with-multiple-testdata-for-each-request-via-newman/6975/3):
>
> Thanks for the material @aamir.ahmed, but can we identify which request data in the array of json input will serve which api request in the collection Do u imply that we need to execute different/multiple newman cmds like –\> newman run -folder api1 -data inputfile1 –\> newman run -folder api2 -data inputfile2 Doing this in an automation fashion requires to maintain a mapping file between api folders and inputfiles Do we have the ability to make this possible in just one command?

May be separating the request in different folders can be a workaround for now.

---

<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:** [November 10, 2020, 7:25am UTC](https://community.postman.com/t/newman-multiple-data-files/17541/5 "2020-11-10T07:25:04Z")

</div>

As you mentioned you’re getting an Auth token from some other process (Cypress) and storing it in a file.

You could capture/reference that in a System Environment Variable at runtime and use that in the Newman command using `--env-var "token=$TOKEN"`

That token variable would resolve a `{{token}}` variable that you might have in the Collection.

Are you running this in a CI pipeline? If so what does that currently look like?

There a lot of assumptions eing made here so perhaps you could expand on your whole process so that we can advise you on a solution.

---

<div class="post-metadata">

**Author:** ![sfreewave](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@sfreewave](https://community.postman.com/u/sfreewave)\
**Post date:** [November 10, 2020, 7:41am UTC](https://community.postman.com/t/newman-multiple-data-files/17541/6 "2020-11-10T07:41:24Z")

</div>

Thanks Danny,  
currently we are using this code in cypress file:

```
 cy.log('Started the login flow - success login')
    cy.visit(authorize_url)
    cy.get('[type="text"].auth0-lock-input')
        .type(this.auth0.email)
        .should('have.value', this.auth0.email)

    cy.get('[type="password"].auth0-lock-input')
        .type(this.auth0.password)
        .should('have.value', this.auth0.password)

    cy.get('.auth0-lock-submit[type="submit"]')
        .click()

    cy.url().should('include', '/callback')

    cy.location({timeout: 5000}).then((loc) => {
        let params_strings = loc.search
        let matches = params_strings.match(/code=([^&]*)/)
        //let code = ''
        if (matches.length > 1) {
            code_HF = matches[1]
        }
        cy.writeFile('./newman/data/oauth_code.json', [{
            **'auth_code': code_HF**
        }])

```

and in our test collection, we need to use the value of ‘auth\_code’. Plz let me know if there is any alternative way possible for accessing the value( that is withoiut redirecting it into oauth\_code.json). Thanks a lot for your help.

---

<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:** [November 10, 2020, 7:52am UTC](https://community.postman.com/t/newman-multiple-data-files/17541/7 "2020-11-10T07:52:11Z")

</div>

Have you looked at using Newman as a library rather than just running this from the CLI?

You could pass that captured value between Cypress and Newman easier. One you install Newman as a dependency in the project, you can create a script to run the Collection.

```auto
const newman = require('newman'); 

newman.run({
    collection: require('collection.json'),
    environment: require('env.json'),
    reporters: 'cli',
    iterationData: 'data.json',
    envVar: [
        { 'key' : 'token', 'value': `${cypress_token}`} 
    ]     
}, function (err) {
	if (err) { throw err; }
    console.log('collection run complete!');
});

```

This is a little rough but hopefully you get where I’m going with it. I can cycle back later and clear it up a bit.

---

<div class="post-metadata">

**Author:** ![sfreewave](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@sfreewave](https://community.postman.com/u/sfreewave)\
**Post date:** [November 10, 2020, 8:07am UTC](https://community.postman.com/t/newman-multiple-data-files/17541/8 "2020-11-10T08:07:25Z")

</div>

sure. Will definitely give a try. Thanks again. Much appreciated.

---

<div class="post-metadata">

**Author:** ![sfreewave](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@sfreewave](https://community.postman.com/u/sfreewave)\
**Post date:** [November 10, 2020, 9:36pm UTC](https://community.postman.com/t/newman-multiple-data-files/17541/9 "2020-11-10T21:36:55Z")

</div>

> [@danny-dainton](#):
>
> `{cypress_token`

Hi Danny,  
Tried using approach mentioned by you. But am stuck in how to export the value of ‘cypress\_token’ from cypress tool. Dont think cypress supports this feature of setting env variables which can be accessed outside the scope of current test specification file.

---

<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:** [November 10, 2020, 9:46pm UTC](https://community.postman.com/t/newman-multiple-data-files/17541/10 "2020-11-10T21:46:24Z")

</div>

Could not read the value from the created cypress file with `fs` or something and store that as a variable to use with the Newman script?

---

<div class="post-metadata">

**Author:** ![allen.vargas](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@allen.vargas](https://community.postman.com/u/allen.vargas)\
**Post date:** [March 2, 2021, 7:01am UTC](https://community.postman.com/t/newman-multiple-data-files/17541/11 "2021-03-02T07:01:17Z")

</div>

Hi @danny-dainton,

I am thinking about this today. My setup is that, all my test cases/data for one endpoint is inside 1 data file. We have multiple endpoints so I also have multiple data files. I am thinking of passing the filenames in the -d option for partial execution.

Thanks and regards,  
Allen
