# Newman for Postman

Using the newman macro provided by the Bionic Metrics platform, its now possible to run your Postman collections. This guide demonstrates how to use macro.newman which utilizes Newman.

# Video Guide

# Exporting a Postman Collection

First, to run your postman collection you must export it to JSON or a URL. To export a public link for your collection, select the more icon on your collection and select Share Collection Then select Get public link and copy the link: Share Collection

Note: this link does not automatically update when you make changes to the collection

Alternatively (see second example), you can export your collection as JSON: select more icon for your collection > Export > Export v2.1 (recommended) and save the JSON file

Export Collection

# Running Newman

# Example 1: Using a URL

In this example we either exported our collection to a public URL or uploaded our collection to a different location (S3, Drive, Dropbox, etc).

const {summary, htmlUrl, jsonUrl} = await macro.newman('https://www.getpostman.com/collections/b4272ca733a9e7739d66');

# Example 2: Passing in Options

You can pass in any of the Newman Options as the second parameter.

const options = {environment: {}};
const {summary, htmlUrl, jsonUrl} = await macro.newman('https://www.getpostman.com/collections/b4272ca733a9e7739d66', options);

# Example 3: Using Collection JSON Directly

You can also pass in the collection JSON directly as the first parameter:

const collection = {"info":{"_postman_id":"5afed2b7-21bf-45aa-a26f-c43bad106c5f","name":"Sample","schema":"https://schema.getpostman.com/json/collection/v2.1.0/collection.json"},"item":[{"name":"GET Version","request":{"method":"GET","header":[],"url":{"raw":"https://api.bionicmetrics.com/version","protocol":"https","host":["api","bionicmetrics","com"],"path":["version"]}},"response":[]}],"protocolProfileBehavior":{}};
const {summary, htmlUrl, jsonUrl} = await macro.newman(collection);

# Results

Results from the Newman run come in three forms:

  1. The Summary Object: Summary Documentation
  2. A JSON report that is retrievable via a URL
  3. An HTML report that is retrievable via a URL
const {summary, htmlUrl, jsonUrl} = await macro.newman(collection);
const failures = _.get(summary, 'run.failures');

// You can use the summary to assert for the test:
if (!_.isEmpty(failures)) throw new Error('some results had failures');

If you have any questions, please contact us on Slack or support@bionicmetrics.com