Use Newman/Postman to Synthetically Monitor API Endpoints

Use Newman/Postman to Synthetically Monitor API Endpoints

Bitbar Monitoring provides a way to monitor mobile applications and APIs using real mobile devices in various location around the world with the option of using real carrier networks. The service supports running scripted mobile tests using eg. the Appium testing framework. Other supported frameworks are XCUITest for iOS and Espresso for Android applications.

Because the way the scripted tests are executed, other approaches for testing mobile applications or endpoints are supported. It is possible to monitor API endpoints using specialized tools that are already used by developers. This example shows how to use Newman to run Postman collection runs at Bitbar Monitoring.


Postman is a graphical tool for writing API requests to test REST services using the JavaScript programming language. The same language that most websites and many mobile applications are nowadays implemented. Postman allows the user to create requests and to store the resulting object for further testing of response values. The tester writes assertions against the receive response object evaluating to passing or failing test scenarios. Postman facilitates the creation of requests and evaluating the received responses.

Newman is the command line companion for running Postman collections. Collections can be viewed as test suites.

Example Monitoring Test

To use Postman and Newman tests, you need to create a scripted test check-in Bitbar Monitoring. The scripted test run is a generic executor run, where a zip file is uploaded and unpacked upon test run execution. The unpacked content is looked for a `pom.xml` file to start a Maven execution (`mvn start`). If this file is not available then a shell file `` is looked for. If this is found then it is executed with `sh`.

Specifically this second approach allows the tester to freely start and do any kind of tests.

First, let’s install Newman by following their getting started guide. The following installs Newman and sets it to our current path.

npm install newman
export PATH=$PATH:$(pwd)/node_modules/.bin

Second, we can clone the test repository containing the Postman test suite that we are interested in executing. In this case the test suite is in Newman’s Github repository. Using a git clone is an easy way of making sure that the test suite is always up to date. Optionally, we could also just add the test directory as part of the zip to be uploaded. This sample contains three different requests, but could of course contain many more. Monitoring runs have no limits to the number of API calls.

git clone

Third, to get access to Newman’s test results, we want to create a Maven results directory.

mkdir -p target/surefire-reports

Finally, we need to call Newman to start executing the above-cloned test suite.

newman run -k --reporters "cli,junit" --reporter-junit-exporter target/surefire-reports newman/examples/sample-collection.json;

The passed parameters are for formatting the test results in the JUnit test syntax and giving the location of the test suite (collection).

Below is a sample script that can be used as the `` script that should be packaged for upload to Monitoring check.


# Install newman
npm config set proxy null
npm config set https-proxy null
npm install newman
export PATH=$PATH:$(pwd)/node_modules/.bin

echo "Updated path is: $PATH"

# clone the newman repo if it's not present (should be by default as
# part of upload)
if [ ! -d "newman" ]; then
echo "Cloning Newman repository"
git clone

# create Maven results directory if it does not exist
if [ ! -d "$LOGS_DIR" ]; then
echo "Creating surefire-reports directory: $LOGS_DIR"
mkdir -p "$LOGS_DIR"

# start sample test
export HTTP_PROXY=
newman run -k --reporters "cli,junit" --reporter-junit-exporter "$LOGS_DIR" newman/examples/sample-collection.json;

Next step is to zip this test script into a package and create the Monitoring check. Running `zip -r` in the directory with the test suite and the test script creates a nice package for upload.

├── newman
│ └── examples
│ ├── find-unique-urls-in-run.js
│ ├── parallel-collection-runs.js
│ ├── read-collection-from-file.js
│ ├── reports
│ │ ├── html-reporter-template-data.json
│ │ ├── sample-collection-report.html
│ │ ├── sample-collection-report.json
│ │ └── sample-collection-report.xml
│ ├── run-collections-in-directory.js
│ ├── sample-collection.json
│ └── v1.postman_collection.json

Creating the Check

Let’s create the Monitoring check for running the Newman test. If you are new to mobile synthetic monitoring, you can check out how to get started with Bitbar Monitoring

Create a monitoring test in Bitbar Monitoring

It does not really matter which mobile environment is selected in the next step, as the test is not using any of the devices.

Select the locations and carriers where your APIs need to be monitored.

Lastly only the check run interval and actions to be taken in case of incidents need to be defined.

The API results become visible in the check run view inside of Monitoring service with all HTTP Archive file information about called endpoints, the call durations and the size of transferred data up or down.


The Beginner’s Guide of Using Appium for Mobile App Testing

Learn all the basics about Appium, how to set it up and how to use it for mobile app testing.