### Newman v5 has been released. Check the [migration guide](MIGRATION.md#migrating-from-v4-to-v5) and [changelog](https://github.com/postmanlabs/newman/blob/v5.0.0/CHANGELOG.yaml#L1) for more details.
_Manage all of your organization's APIs in Postman, with the industry's most complete API development environment._
# newman _the cli companion for postman_ [](https://travis-ci.com/postmanlabs/newman) [](https://codecov.io/gh/postmanlabs/newman)
Newman is a command-line collection runner for Postman. It allows you to effortlessly run and test a Postman collection directly from the command-line. It is built with extensibility in mind so that you can easily integrate it with your continuous integration servers and build systems.
## Table of contents
1. [Getting Started](#getting-started)
2. [Usage](#usage)
1. [Using Newman CLI](#using-newman-cli)
2. [Using Newman as a Library](#using-newman-as-a-library)
3. [Using Reporters with Newman](#using-reporters-with-newman)
3. [Command Line Options](#command-line-options)
1. [newman-options](#newman-options)
2. [newman-run](#newman-run-collection-file-source-options)
3. [SSL](#ssl)
4. [Configuring Proxy](#configuring-proxy)
4. [API Reference](#api-reference)
1. [newman run](#newmanrunoptions-object--callback-function--run-eventemitter)
2. [Run summary object](#newmanruncallbackerror-object--summary-object)
3. [Events emitted during a collection run](#newmanrunevents)
5. [Reporters](#reporters)
1. [Configuring Reporters](#configuring-reporters)
2. [CLI Reporter](#cli-reporter)
3. [JSON Reporter](#json-reporter)
4. [JUnit Reporter](#junitxml-reporter)
5. [HTML Reporter](#html-reporter)
6. [External Reporters](#external-reporters)
1. [Using External Reporters](#using-external-reporters)
2. [Creating Your Own Reporter](#creating-your-own-reporter)
7. [File Uploads](#file-uploads)
8. [Using Newman with the Postman API](#using-newman-with-the-postman-api)
9. [Using Newman in Docker](#using-newman-in-docker)
10. [Using Socks Proxy](#using-socks-proxy)
11. [Migration Guide](#migration-guide)
12. [Compatibility](#compatibility)
13. [Contributing](#contributing)
14. [Community Support](#community-support)
15. [License](#license)
## Getting started
To run Newman, ensure that you have Node.js >= v10. [Install Node.js via package manager](https://nodejs.org/en/download/package-manager/).
### Installation
The easiest way to install Newman is using NPM. If you have Node.js installed, it is most likely that you have NPM installed as well.
```console
$ npm install -g newman
```
This installs Newman globally on your system allowing you to run it from anywhere. If you want to install it locally, Just remove the `-g` flag.
#### Using Homebrew
Install Newman globally on your system using Homebrew.
```console
$ brew install newman
```
[back to top](#table-of-contents)
## Usage
### Using Newman CLI
The `newman run` command allows you to specify a collection to be run. You can easily export your Postman
Collection as a json file from the [Postman App](https://www.postman.com/downloads/) and run it using Newman.
```console
$ newman run examples/sample-collection.json
```
If your collection file is available as an URL (such as from our [Cloud API service](https://api.getpostman.com)),
Newman can fetch your file and run it as well.
```console
$ newman run https://www.getpostman.com/collections/631643-f695cab7-6878-eb55-7943-ad88e1ccfd65-JsLv
```
For the complete list of options, refer the [Command Line Options](#command-line-options) section below.

### Using Newman as a Library
Newman can be easily used within your JavaScript projects as a Node.js module. The entire set of Newman CLI functionality is available for programmatic use as well. The following example runs a collection by reading a JSON collection file stored on disk.
```javascript
const newman = require('newman'); // require newman in your project
// call newman.run to pass `options` object and wait for callback
newman.run({
collection: require('./sample-collection.json'),
reporters: 'cli'
}, function (err) {
if (err) { throw err; }
console.log('collection run complete!');
});
```
For the complete list of options, refer the [API Reference](#api-reference) section below.
### Using Reporters with Newman
Reporters provide information about the current collection run in a format that is easy to both: disseminate and assimilate.
Reporters can be configured using the `-r` or `--reporters` options. Inbuilt reporters in newman are: `cli`, `json`, `junit`, `progress` and `emojitrain`.
CLI reporter is enabled by default when Newman is used as a CLI, you do not need to specifically provide the same as part of reporters option. However, enabling one or more of the other reporters will result in no CLI output. Explicitly enable the CLI option in such a scenario. Check the example given below using the CLI and JSON reporters:
```console
$ newman run examples/sample-collection.json -r cli,json
```
For more details on [Reporters](#reporters) and writing your own [External Reporters](#external-reporters) refer to their corresponding sections below.
[back to top](#table-of-contents)
## Command Line Options
### `newman [options]`
- `-h`, `--help`
Show command line help, including a list of options, and sample use cases.
- `-v`, `--version`
Displays the current Newman version, taken from [package.json](https://github.com/postmanlabs/newman/blob/master/package.json)
### `newman run [options]`
- `-e `, `--environment `
Specify an environment file path or URL. Environments provide a set of variables that one can use within collections.
[Read More](https://learning.postman.com/docs/postman/variables-and-environments/managing-environments/)
- `-g `, `--globals `
Specify the file path or URL for global variables. Global variables are similar to environment variables but have a lower
precedence and can be overridden by environment variables having the same name.
- `-d `, `--iteration-data `
Specify a data source file (JSON or CSV) to be used for iteration as a path to a file or as a URL.
[Read More](https://learning.postman.com/docs/postman/collection-runs/working-with-data-files/)
- `-n `, `--iteration-count `
Specifies the number of times the collection has to be run when used in conjunction with iteration data file.
- `--folder `
Run requests within a particular folder/folders or specific requests in a collection. Multiple folders or requests can be specified by using
--folder multiple times, like so: --folder f1 --folder f2 --folder r1 --folder r2.
- `--working-dir `
Set the path of the working directory to use while reading files with relative paths. Default to current directory.
- `--no-insecure-file-read`
Prevents reading of files situated outside of the working directory.
- `--export-environment `
The path to the file where Newman will output the final environment variables file before completing a run.
- `--export-globals `
The path to the file where Newman will output the final global variables file before completing a run.
- `--export-collection `
The path to the file where Newman will output the final collection file before completing a run.
- `--timeout `
Specify the time (in milliseconds) to wait for the entire collection run to complete execution.
- `--timeout-request `
Specify the time (in milliseconds) to wait for requests to return a response.
- `--timeout-script `
Specify the time (in milliseconds) to wait for scripts to complete execution.
- `-k`, `--insecure`
Disables SSL verification checks and allows self-signed SSL certificates.
- `--ignore-redirects`
Prevents newman from automatically following 3XX redirect responses.
- `--delay-request`
Specify the extent of delay between requests (milliseconds).
- `--cookie-jar `
Specify the file path for a JSON Cookie Jar. Uses [`tough-cookie`](https://github.com/salesforce/tough-cookie) to deserialize the file.
- `--export-cookie-jar `
The path to the file where Newman will output the final cookie jar file before completing a run. Uses `tough-cookie`'s serialize method.
- `--bail [optional modifiers]`
Specify whether or not to stop a collection run on encountering the first test script error.
Can optionally accept modifiers, currently include `folder` and `failure`.
`folder` allows you to skip the entire collection run in case an invalid folder
was specified using the `--folder` option or an error was encountered in general.
On the failure of a test, `failure` would gracefully stop a collection run after completing the current test script.
- `-x`, `--suppress-exit-code`
Specify whether or not to override the default exit code for the current run.
- `--color `
Enable or Disable colored CLI output. The color value can be any of the three: `on`, `off` or `auto`*(default)*.
With `auto`, Newman attempts to automatically turn color on or off based on the color support in the terminal.
This behaviour can be modified by using the `on` or `off` value accordingly.
- `--disable-unicode`
Specify whether or not to force the unicode disable option. When supplied, all symbols in the output will be replaced
by their plain text equivalents.
- `--global-var "="`
Allows the specification of global variables via the command line, in a key=value format. Multiple CLI global variables
can be added by using `--global-var` multiple times, like so: `--global-var "foo=bar" --global-var "alpha=beta"`.
- `--env-var "="`
Allows the specification of environment variables via the command line, in a key=value format. Multiple CLI environment variables
can be added by using `--env-var` multiple times, like so: `--env-var "foo=bar" --env-var "alpha=beta"`.
- `--verbose`
Show detailed information of collection run and each request sent.
### SSL
#### Client Certificates
Client certificates are an alternative to traditional authentication mechanisms. These allow their users to make authenticated requests to a server, using a public certificate, and an optional private key that verifies certificate ownership. In some cases, the private key may also be protected by a secret passphrase, providing an additional layer of authentication security.
Newman supports SSL client certificates, via the following CLI options:
#### Using a single SSL client certificate
- `--ssl-client-cert`
The path to the public client certificate file.
- `--ssl-client-key`
The path to the private client key (optional).
- `--ssl-client-passphrase`
The secret passphrase used to protect the private client key (optional).
#### Using SSL client certificates configuration file (supports multiple certificates per run)
- `--ssl-client-cert-list`
The path to the SSL client certificate list configuration file (JSON format). See [examples/ssl-client-cert-list.json](https://github.com/postmanlabs/newman/blob/develop/examples/ssl-client-cert-list.json).
This option allows setting different SSL client certificate according to URL or hostname.
This option takes precedence over `--ssl-client-cert`, `--ssl-client-key` and `--ssl-client-passphrase` options. If there is no match for the URL in the list, these options are used as fallback.
#### Trusted CA
When it is not wanted to use the `--insecure` option, additionally trusted CA certificates can be provided like this:
- `--ssl-extra-ca-certs`
The path to the file, that holds one or more trusted CA certificates in PEM format
### Configuring Proxy
Newman can also be configured to work with proxy settings via the following environment variables:
* `HTTP_PROXY` / `http_proxy`
* `HTTPS_PROXY` / `https_proxy`
* `NO_PROXY` / `no_proxy`
For more details on using these variables, [refer here](https://github.com/postmanlabs/postman-request/blob/master/README.md#controlling-proxy-behaviour-using-environment-variables).
[back to top](#table-of-contents)
## API Reference
### newman.run(options: _object_ , callback: _function_) => run: EventEmitter
The `run` function executes a collection and returns the run result to a callback function provided as parameter. The
return of the `newman.run` function is a run instance, which emits run events that can be listened to.
| Parameter | Description |
|-----------|---------------|
| options | This is a required argument and it contains all information pertaining to running a collection.
_Required_ Type: `object` |
| options.collection | The collection is a required property of the `options` argument. It accepts an object representation of a Postman Collection which should resemble the schema mentioned at [https://schema.getpostman.com/](https://schema.getpostman.com/). The value of this property could also be an instance of Collection Object from the [Postman Collection SDK](https://github.com/postmanlabs/postman-collection).
As `string`, one can provide a URL where the Collection JSON can be found (e.g. [Postman Cloud API](https://api.getpostman.com/) service) or path to a local JSON file.
_Required_ Type: `object\|string` [PostmanCollection](https://github.com/postmanlabs/postman-collection/wiki#Collection) |
| options.environment | One can optionally pass an environment file path or URL as `string` to this property and that will be used to read Postman Environment Variables from. This property also accepts environment variables as an `object`. Environment files exported from Postman App can be directly used here.
_Optional_ Type: `object\|string` |
| options.envVar | One can optionally pass environment variables as an array of key-value string object pairs. It will be used to read Postman Environment Variables as well as overwrite environment variables from `options.environments`.
_Optional_ Type: `array\|object` |
| options.globals | Postman Global Variables can be optionally passed on to a collection run in form of path to a file or URL. It also accepts variables as an `object`.
_Optional_ Type: `object\|string` |
| options.globalVar | One can optionally pass global environment variables as an array of key-value string object pairs. It will be used to read Postman Global Environment Variables as well as overwrite global environment variables from `options.globals`.
_Optional_ Type: `array\|object` |
| options.iterationCount | Specify the number of iterations to run on the collection. This is usually accompanied by providing a data file reference as `options.iterationData`.
_Optional_ Type: `number`, Default value: `1` |
| options.iterationData | Path to the JSON or CSV file or URL to be used as data source when running multiple iterations on a collection.
_Optional_ Type: `string` |
| options.folder | The name or ID of the folder/folders (ItemGroup) in the collection which would be run instead of the entire collection.
_Optional_ Type: `string\|array` |
| options.workingDir | The path of the directory to be used as working directory.
_Optional_ Type: `string`, Default value: `Current Directory` |
| options.insecureFileRead | Allow reading files outside of working directory.
_Optional_ Type: `boolean`, Default value: `true` |
| options.timeout | Specify the time (in milliseconds) to wait for the entire collection run to complete execution.
_Optional_ Type: `number`, Default value: `Infinity` |
| options.timeoutRequest | Specify the time (in milliseconds) to wait for requests to return a response.
_Optional_ Type: `number`, Default value: `Infinity` |
| options.timeoutScript | Specify the time (in milliseconds) to wait for scripts to return a response.
_Optional_ Type: `number`, Default value: `Infinity` |
| options.delayRequest | Specify the time (in milliseconds) to wait for between subsequent requests.
_Optional_ Type: `number`, Default value: `0` |
| options.ignoreRedirects | This specifies whether newman would automatically follow 3xx responses from servers.
_Optional_ Type: `boolean`, Default value: `false` |
| options.bail | A switch to specify whether or not to gracefully stop a collection run (after completing the current test script) on encountering the first error. Takes additional modifiers as arguments to specify whether to end the run with an error for invalid name or path.
Available modifiers: `folder` and `failure`. eg. `bail : ['folder']`
_Optional_ Type: `boolean\|object`, Default value: `false` |
| options.suppressExitCode | If present, allows overriding the default exit code from the current collection run, useful for bypassing collection result failures. Takes no arguments.
_Optional_ Type: `boolean`, Default value: `false` |
| options.reporters | Specify one reporter name as `string` or provide more than one reporter name as an `array`.
Available reporters: `cli`, `json`, `junit`, `progress` and `emojitrain`.
_Optional_ Type: `string\|array` |
| options.reporter | Specify options for the reporter(s) declared in `options.reporters`. e.g. `reporter : { junit : { export : './xmlResults.xml' } }` e.g. `reporter : { html : { export : './htmlResults.html', template: './customTemplate.hbs' } }`
_Optional_ Type: `string` |
| options.sslClientCertList | The path to the client certificate configuration list file. This option takes precedence over `sslClientCert`, `sslClientKey` and `sslClientPassphrase`. When there is no match in this configuration list, `sslClientCert` is used as fallback.
_Optional_ Type: `string\|array` |
| options.sslExtraCaCerts | The path to the file, that holds one or more trusted CA certificates in PEM format.
_Optional_ Type: `string` |
| options.requestAgents | Specify the custom requesting agents to be used when performing HTTP and HTTPS requests respectively. Example: [Using Socks Proxy](#using-socks-proxy)
_Optional_ Type: `object` |
| options.cookieJar | One can optionally pass a CookieJar file path as `string` to this property and that will be deserialized using [`tough-cookie`](https://github.com/salesforce/tough-cookie). This property also accepts a `tough-cookie` CookieJar instance.
_Optional_ Type: `object\|string` |
| options.newmanVersion | The Newman version used for the collection run.
_This will be set by Newman_ |
| callback | Upon completion of the run, this callback is executed with the `error`, `summary` argument.
_Required_ Type: `function` |
### newman.run~callback(error: _object_ , summary: _object_)
The `callback` parameter of the `newman.run` function receives two arguments: (1) `error` and (2) `summary`
| Argument | Description |
|-----------|---------------|
| error | In case newman faces an error during the run, the error is passed on to this argument of callback. By default, only fatal errors, such as the ones caused by any fault inside Newman is passed on to this argument. However, setting `abortOnError:true` or `abortOnFailure:true` as part of run options will cause newman to treat collection script syntax errors and test failures as fatal errors and be passed down here while stopping the run abruptly at that point.
Type: `object` |
| summary | The run summary will contain information pertaining to the run.
Type: `object` |
| summary.error | An error object which if exists, contains an error message describing the message
Type: `object` |
| summary.collection | This object contains information about the collection being run, it's requests, and their associated pre-request scripts and tests.
Type: `object` |
| summary.environment | An object with environment variables used for the current run, and the usage status for each of those variables.
Type: `object` |
| summary.globals | This object holds details about the globals used within the collection run namespace.
Type: `object` |
| summary.run | A cumulative run summary object that provides information on .
Type: `object` |
| summary.run.stats | An object which provides details about the total, failed, and pending counts for pre request scripts, tests, assertions, requests, and more.
Type: `object` |
| summary.run.failures | An array of failure objects, with each element holding details, including the assertion that failed, and the request.