# How to capture response body data in Newman result report

**URL:** <https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944>\
**Category:** Help Hub\
**Created:** [February 15, 2018, 12:20pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944 "2018-02-15T12:20:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![prerna.ise41](https://avatars.discourse-cdn.com/v4/letter/p/f4b2a3/32.png) [@prerna.ise41](https://community.postman.com/u/prerna.ise41)\
**Post date:** [February 15, 2018, 12:20pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/1 "2018-02-15T12:20:55Z")

</div>

I want to capture response body data in Newman result report so that I will get to know for which reason my APIs are failing.

I need help.  
Please let me know if anyone knows.

---

<div class="post-metadata">

**Author:** ![rmlira](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/rmlira/32/232_2.png) [@rmlira](https://community.postman.com/u/rmlira)\
**Post date:** [February 16, 2018, 12:05pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/2 "2018-02-16T12:05:07Z")

</div>

Hi. On newman you could use --reporter-html-template to indicate the path of the handlebars template that will be used to generate the html report. The default html reporter uses an generic template ‘template-default.hbs’ in ‘\node\_modules\newman\lib\reporters\html’ you could copy it and make your own template.

To get the reponse body data in the report, edit your handlebars template to iterate over ‘response’ object… the ‘body’ property contains the response data.

example:

- To run newman with custom template

NEWMAN\_PATH run YOUR\_COLLECTION.json --reporters html,cli --reporter-html-export PATH\_TO\_REPORT.html --reporter-html-template PATH\_TO\_YOUR\_TEMPLATE.hbs

- On your custom template (.hbs) file

inside block ‘{{#\*inline “aggregations”}} {{#each executions}}’ add a ‘div’ with ‘{{response.body}}’ this will make handlebars iterate over each executions in json result and print the response.body data inside a div.

This handlebars (.hbs) file is just an html file with entries that will be populated by the handlebars. For more info: [http://handlebarsjs.com/](http://handlebarsjs.com/)

---

<div class="post-metadata">

**Author:** ![prerna.ise41](https://avatars.discourse-cdn.com/v4/letter/p/f4b2a3/32.png) [@prerna.ise41](https://community.postman.com/u/prerna.ise41)\
**Post date:** [March 27, 2018, 9:56am UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/3 "2018-03-27T09:56:55Z")

</div>

I installed handlebars but I didn’t understand how to execute/use this. Can you help me?

---

<div class="post-metadata">

**Author:** ![gopikrishna4595](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gopikrishna4595/32/514_2.png) [@gopikrishna4595](https://community.postman.com/u/gopikrishna4595)\
**Post date:** [March 29, 2018, 11:59am UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/4 "2018-03-29T11:59:56Z")

</div>

Hi @rmlira

i had added the a div as you explained (PFA :postmanReport).  
i dont see respone in the report (PFA: ActualReport), can you tell where i went wrong ?

 ![postmanReport](https://us1.discourse-cdn.com/getpostman/original/3X/5/1/51fe086449be027d87fa3c9ee7e7d5829485fd7a.png)

---

<div class="post-metadata">

**Author:** ![gopikrishna4595](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gopikrishna4595/32/514_2.png) [@gopikrishna4595](https://community.postman.com/u/gopikrishna4595)\
**Post date:** [March 29, 2018, 12:00pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/5 "2018-03-29T12:00:45Z")

</div>

@rmlira  
This is the report generated,

 ![ActualReport](https://us1.discourse-cdn.com/getpostman/original/3X/f/2/f2c872e4809c862753a7e4aee425051fd3231a5a.png)

---

<div class="post-metadata">

**Author:** ![rmlira](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/rmlira/32/232_2.png) [@rmlira](https://community.postman.com/u/rmlira)\
**Post date:** [March 29, 2018, 1:52pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/6 "2018-03-29T13:52:31Z")

</div>

Hi @gopikrishna4595 … you must use {{response.body}} outside the {{#with request}} block… 'cause the response.body is a child from executions directly… and not from request. I think this will solve your problem. Try it, let me now if it works.

---

<div class="post-metadata">

**Author:** ![rmlira](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/rmlira/32/232_2.png) [@rmlira](https://community.postman.com/u/rmlira)\
**Post date:** [March 29, 2018, 2:05pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/7 "2018-03-29T14:05:15Z")

</div>

Hi, newman already comes with handlebars installed, you don’t need to install it… to get response.body in html report you just need to use a template that reads the response body.

In order to do this you must run Newman with the parameter ‘–reporter-html-template’ informing your template file. To create a template file you could copy the default template that comes with Newman (\node\_modules\newman\lib\reporters\html) and create your own in any directory, just pass the fullpath for the file to --reporter-html-template. Do you have any other specific questions?

---

<div class="post-metadata">

**Author:** ![gopikrishna4595](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gopikrishna4595/32/514_2.png) [@gopikrishna4595](https://community.postman.com/u/gopikrishna4595)\
**Post date:** [March 30, 2018, 11:57am UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/8 "2018-03-30T11:57:47Z")

</div>

> [@rmlira](#):
>
> {#with request}}

Thank you @rmlira 👏🏽,

Using {{response.body}} outside the {{#with request}} helped to get a response in the report.

But i see a different problem  
I executed a collection through newman and generated a report with the modified HTML template.  
The problem is when collection is run with iteration, in the report i’m _unable_ to open all the requests, only first two requests are able to open in the report generated.  
Below is the command used.

```
newman run Sample.postman_collection.json -d CSVFILE.csv -n 6 -r html --reporters cli,html --reporter-html-template C:\Users\gopikrishna\Documents\colouredDefault.hbs --reporter-html-export C:\Users\gopikrishna\Desktop\Doubts\Report201803.html

```

Below link is of Report file generated, Postman Collection.  
[https://drive.google.com/open?id=1a1OaZA7Gs7EnSq2vLZeQLgI1Wi8MwcHU](https://drive.google.com/open?id=1a1OaZA7Gs7EnSq2vLZeQLgI1Wi8MwcHU)

[Postman Files](https://drive.google.com/open?id=1a1OaZA7Gs7EnSq2vLZeQLgI1Wi8MwcHU)

Plz have a look at the Report File Generated.

i think, the problem lies in the HTML code of Template.

can you help to get over this ?

---

<div class="post-metadata">

**Author:** ![rmlira](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/rmlira/32/232_2.png) [@rmlira](https://community.postman.com/u/rmlira)\
**Post date:** [March 30, 2018, 11:24pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/9 "2018-03-30T23:24:18Z")

</div>

Yes… this problem occurs because in template it creates a div.panel-group for each execution, and the id attribute of this div is ‘collapse-request-{{item.id}}’. This way, for each iteration it will create 2 new div’s with same id, because item.id is the same in each iteration… this causes javascript to not work properly. When you click in a div it navigates throw DOM to find the first panel that must expand/collapse with the target id, as div’s has same id it always will use only first div. ([JavaScript · Bootstrap](https://getbootstrap.com/docs/3.3/javascript/#collapse))

To fix this, we should increment the id attribute with index of iteration… handlebars has a builtin helper that brings the index to us.

On template in block:

```
{{#*inline "aggregations"}}
    {{#each executions}}

```

you must find each ‘{{item.id}}’ and replace then with ‘{{item.id}}-{{@index}}’, this way we guarantee that each div has a unique id, and javascript could work properly.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/e/0/e03c3d2ade51bf84011f41207c1b236b62cc057d.png)  
Try it, let me now if it works.

---

<div class="post-metadata">

**Author:** ![gopikrishna4595](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gopikrishna4595/32/514_2.png) [@gopikrishna4595](https://community.postman.com/u/gopikrishna4595)\
**Post date:** [March 31, 2018, 9:17pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/10 "2018-03-31T21:17:02Z")

</div>

Hi @rmlira,

with the addition {{@index}} in id, working perfectly.👌🏼

Now, able to open all the requests in the generated report.  
and when i went through all the responses in the report, i found that all the responses are same which was generated for the first request in the iteration.

 ![sameResponse](https://us1.discourse-cdn.com/getpostman/original/3X/5/1/51c40fa509160c35cc64dffdce26587f77b3d493.png)

The same issue is seen for URL field in the {{#with request}} loop in the generated report.

any inputs on this ?

---

<div class="post-metadata">

**Author:** ![rmlira](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/rmlira/32/232_2.png) [@rmlira](https://community.postman.com/u/rmlira)\
**Post date:** [April 2, 2018, 1:18pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/11 "2018-04-02T13:18:08Z")

</div>

This problem occurs because newman original html reporter was made for simple scenarios, without iterations.

To repair this problem will be necessary to edit the newman html reporter source, or create your own html reporter.

To edit newman html reporter you will need to access the folder node\_modules/newman/lib/reporters/html in this folder there’s an index.js file, you need to edit this file to make it works properly on iterations.

The problem occurs because it considers only ‘currentExecution.id’ when aggregating data, we need it to consider currentExecution.id and currentExecution.response.id… cause our execution.id is the same but response is not. In order to do this you will need to replace multiple lines in file as follows:

line ~65:  
`executionId = currentExecution.id;`  
replace with:  
`executionId = currentExecution.id + currentExecution.response.id;`

line ~92:  
`items[reducedExecution.item.id] = reducedExecution;`  
replace with:  
`items[reducedExecution.item.id + reducedExecution.response.id] = reducedExecution;`

line ~126 and ~127:  
`current = _.merge(items[execution.item.id], {`  
`assertions: _.values(assertions[execution.item.id]),`  
replace with:  
`current = _.merge(items[execution.item.id + execution.response.id], {`  
`assertions: _.values(assertions[execution.item.id + execution.response.id]),`

line ~132:  
`cumulativeTests: netTestCounts[execution.item.id]`  
replace with:  
`cumulativeTests: netTestCounts[execution.item.id + execution.response.id]`

this will make it works with iterations, but I didn’t fully analyze the source, in time I’ll consolidate this and others improvements in a new html reporter, you can try this modifications in your own risk, in any case just restore the original index.js file.

---

<div class="post-metadata">

**Author:** ![gopikrishna4595](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gopikrishna4595/32/514_2.png) [@gopikrishna4595](https://community.postman.com/u/gopikrishna4595)\
**Post date:** [April 2, 2018, 2:50pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/12 "2018-04-02T14:50:04Z")

</div>

working perfect.

i had also added the request body to the report just like response body.

Thank you.👏🏽

---

<div class="post-metadata">

**Author:** ![gopikrishna4595](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gopikrishna4595/32/514_2.png) [@gopikrishna4595](https://community.postman.com/u/gopikrishna4595)\
**Post date:** [April 8, 2018, 8:48pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/13 "2018-04-08T20:48:42Z")

</div>

Hi @rmlira,

How are you doing ?

with the modifications made in index.js file, let us say in the executed collection has 3 requests and iteration is set for 30. a total of 90 requests is seen in the report.

instead of that can we have like request tab panel consisting of sub tabs(iterations).

To make the report look good  
as a noob, i created collapsible tab for request and response, changed the colors. 😛

As of now, i created a tab for iteration1.  
iteration2 and iteration3 are dummy tabs with no data.

 ![Postman%20Tabs](https://us1.discourse-cdn.com/getpostman/original/3X/1/1/110b6e1cb6f8b53a5ea34a0eacc3aa2c379a1ae3.png)

how can we create “n” no.of tabs upon the no.of iterations and pass the data into it.

Following is the drive link of the latest hbs file and index.js file.👇🏼

[PostmanFiles-2](https://drive.google.com/drive/folders/1WNsjQOVMhHgG8bGQsIQM7ApDZf13Gxj2?usp=sharing)

[https://drive.google.com/drive/folders/1WNsjQOVMhHgG8bGQsIQM7ApDZf13Gxj2?usp=sharing](https://drive.google.com/drive/folders/1WNsjQOVMhHgG8bGQsIQM7ApDZf13Gxj2?usp=sharing)

and i’m able to print the response body in Pretty Json String for **REST** requests. 😊  
(by default, it is in string format which doesn’t look good)

I’m still working on **soap/Xml** requests.

With the files shared to you, as of now ,you cannot get pretty json with the files shared i screwed up the code 🤯 while trying for Pretty Xml format.  
you can **un-comment** the code and Feel free to check

---

<div class="post-metadata">

**Author:** ![rmlira](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/rmlira/32/232_2.png) [@rmlira](https://community.postman.com/u/rmlira)\
**Post date:** [April 13, 2018, 2:21pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/14 "2018-04-13T14:21:46Z")

</div>

Hi @gopikrishna4595, sorry for the delay.

To make this modifications we’ll need to edit newman html reporter index.js file again. So again access the folder: node\_modules/newman/lib/reporters/html and open index.js file.

line ~35:  
`AGGREGATED_FIELDS = ['item', 'request', 'response'],`  
replace with:  
`AGGREGATED_FIELDS = ['cursor', 'item', 'request', 'response'],`

![image](https://us1.discourse-cdn.com/getpostman/original/3X/9/b/9b65d26423842e80ef3c6fb3f9c4fd19dd993b0a.png)

line ~124:  
(after `parent = execution.item.parent(),`) add a new line with :  
`iteration = execution.cursor.iteration,`

line ~141  
(after `id: parent.id,`) add a new line with:  
`iteration: iteration,`

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/a/7/a7747462560cc876dd7808d81815596792ff7199.png)

Once you make these modifications we can now edit the template to create the tabs. To create the tabs dinamically according to the number of iterations we will need to add some javascript code. So in `<head>` block add:

line ~23:

```
<script type="text/javascript">
    "use strict";

window.onload = function () {

  // hides all blocks of response
  var allItems = document.querySelectorAll('[class*=iteration-]');
  allItems.forEach(function(elem){
    elem.style.display = 'none';
  });

  {{#with summary}} {{#with stats}}
  let totalIterations = {{iterations.total}};
  {{/with}} {{/with}}

  let menu = document.querySelector('#execution-menu .nav');

  for(var i = 0; i < totalIterations; i++)
  {
    let li = document.createElement('li');
    li.appendChild(document.createTextNode('Iteration - ' + i));
    li.setAttribute('id', 'iteration-' + i);

    li.addEventListener('click', function() {

      let allItems = document.querySelectorAll('[class*=iteration-]');
      allItems.forEach(function(elem) {
        elem.style.display = 'none';
      })

      let items = document.querySelectorAll("." + this.id);
      items.forEach(function(elem) {
        elem.style.display = elem.style.display == 'block' ? 'none' : 'block';
      })
    });

    menu.appendChild(li);
  }
}</script>

```

This block of code only sets css property ‘display’ to ‘none’ in all blocks of response data and populate an menu list with iteration-\* menu according to number of iterations provided by handlebars in ‘totalIterations’ variable. I use pure javascript but feel free to improve it with jQuery…

Now after the ‘Requests’ title (line ~97 `<h4>Requests</h4>`) we will create our tab menu so add a new line with this block:

```
<div id="execution-menu">
        <ul class="nav nav-tabs">
        </ul>
    </div>

```

Then put the `{{#each aggregations}}....{{/each}}` block inside a div `<div class="tab-content" id="execution-data">`.

The first div inside `{{#each aggregations}}` block is: `<div class="panel-group" id=....` we need to add a class in this div. So it will be: `<div class="panel-group iteration-{{parent.iteration}}" id=`

Once you make these modifications we need to replace every `{{parent.id}}` with `{{parent.id}}-{{parent.iteration}}`

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/f/8/f8a62be360df2ad3bba85561815f594a5f12e4b9.png)

Then in `{{#each executions}}` block (line ~129) we need to replace every `{{item.id}}` with `{{item.id}}-{{cursor.iteration}}`

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/2/7/276b51a93a5d2c001c482f456b596fee2343fefa.png)

And it’s done. These modifications will create a tab menu, when you click in each menu it will display only the requests corresponding to that iteration.

Try it, let me now if it works.

---

<div class="post-metadata">

**Author:** ![rmlira](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/rmlira/32/232_2.png) [@rmlira](https://community.postman.com/u/rmlira)\
**Post date:** [April 13, 2018, 4:20pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/15 "2018-04-13T16:20:33Z")

</div>

I’m still working on a better approach. As soon as possible I return with the result.

---

<div class="post-metadata">

**Author:** ![gopikrishna4595](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gopikrishna4595/32/514_2.png) [@gopikrishna4595](https://community.postman.com/u/gopikrishna4595)\
**Post date:** [April 13, 2018, 4:25pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/16 "2018-04-13T16:25:22Z")

</div>

Thank you @rmlira for succour,

with these changes tabs are not observed. checked multiple times.

 ![postman%20tabs](https://us1.discourse-cdn.com/getpostman/original/3X/e/a/eae8d63d6c22bd0630fb94c89e7ed74f5f528d58.png)

 ![postman%20tabs%201](https://us1.discourse-cdn.com/getpostman/original/3X/4/c/4c390903625fe5e7b5088ae786e7b21dc882b4be.png)

can these latest changes can be added to the same file where we made changes earlier (which let us to open each request separately.) ?

---

<div class="post-metadata">

**Author:** ![rmlira](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/rmlira/32/232_2.png) [@rmlira](https://community.postman.com/u/rmlira)\
**Post date:** [April 13, 2018, 4:37pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/17 "2018-04-13T16:37:42Z")

</div>

Yes, you must use the index.js (reporter html file) with previous changes and just add these new ones. If error persists can you show me your index.js file and your hbs template?

---

<div class="post-metadata">

**Author:** ![gopikrishna4595](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gopikrishna4595/32/514_2.png) [@gopikrishna4595](https://community.postman.com/u/gopikrishna4595)\
**Post date:** [April 13, 2018, 4:46pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/18 "2018-04-13T16:46:19Z")

</div>

Yes Renan Lira, added these changes to the previous changes. Tabs are not seen.

Following are the files with Google Drive link  
[Postman Reports with Tabs](https://drive.google.com/drive/folders/1v3Ra-JpnVuhVjW_V2J6R5Kx0NaOfM2rl?usp=sharing)

---

<div class="post-metadata">

**Author:** ![rmlira](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/rmlira/32/232_2.png) [@rmlira](https://community.postman.com/u/rmlira)\
**Post date:** [April 13, 2018, 5:26pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/19 "2018-04-13T17:26:53Z")

</div>

I make a test using your template and the reporter… and it works. I’m testing on chrome. I’ll make more tests, do you know if any error appears in console?

---

<div class="post-metadata">

**Author:** ![gopikrishna4595](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gopikrishna4595/32/514_2.png) [@gopikrishna4595](https://community.postman.com/u/gopikrishna4595)\
**Post date:** [April 13, 2018, 5:56pm UTC](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944/20 "2018-04-13T17:56:43Z")

</div>

i had checked multiple times Renan Lira even in chrome,  
executed the script several times, but tabs are not seen, just their text is seen on the top.

if possible can you drop your files in the

[Postman Report Tabs](https://drive.google.com/drive/folders/1v3Ra-JpnVuhVjW_V2J6R5Kx0NaOfM2rl?usp=sharing)

i’ll try with those files.

and just for reference, can you attach a image how you are observing .

[Next page](https://community.postman.com/t/how-to-capture-response-body-data-in-newman-result-report/944.md?page=2)
