Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export/download Response Body into an external file from Postman Collection Runner Results?

I am working on a project where I have to hit a web service multiple times with different values of a variable

For example, http://mywebservice.com?variable1={{value}}

and different values are passed using Postman collection runner.

I want to download the response body of all the requests into a file. How do I do that?

like image 475
Dinesh Singh Avatar asked Jan 05 '18 12:01

Dinesh Singh


People also ask

How do I export response body in Postman runner?

Open the collection runner, Select the required collection and request, select the “save responses” checkbox and run it. click on individual request, select the response body and manually copy the response and paste it to locally which is not feasibly because we can't do manually one by one for 100 requests.

How can you save the responses of API to a file in Postman?

Execute the download request Click the "Send" button. The response contains unreadable text, because the API returns a compressed CSV file. Click the "Save Response" button in Postman, select the "Save to a file" option and choose a location on your local machine to save the . zip file to.

How do you save a response in collection runner?

Open the collection run in the Runner. You can also access the collection run using History in the sidebar if you don't have the run open. Select Export Results at the top right to download the run. Choose a location to save your downloaded collection run, then select Save.


1 Answers

I faced this situation and solved it by using the CLI tool newman

First you need to export your collection and the environment as JSON files. Then install newman using the command:

sudo npm install -g newman

Then if you want a neat looking HTML report for the results, then first install the external reported newman-reporter-html with the below command

sudo npm install -g newman-reporter-html

You can generate the report now by running the following command:

newman run <path to your collection json file> -e <path to your environment json file> -r cli,html

By default, the HTML file will not contain the request and response body. In order to render that, first download the default handlebars template and then tweak it a little bit. You can find the default handlebars template here. Download the file and save it as template.hbs. Then open it in any editor and look for the code where it is rendering the Status Code. It might look like this:

<div class="col-md-12">&nbsp;</div>
<br/><div class="col-md-4">Status code</div><div class="col-md-8">{{response.code}}</div><br/>

Below this part, add the following lines:

<div class="col-md-12">&nbsp;</div>
<br/><div class="col-md-4">Request body</div>
<div class="col-md-8">
    <textarea class="json" disabled rows="8" cols="70">
        {{request.body}}
    </textarea>
</div><br/>
<div class="col-md-12">&nbsp;</div>
<br/><div class="col-md-4">Response body</div>
<div class="col-md-8">
    <textarea class="json" disabled rows="8" cols="70">
        {{response.body}}
    </textarea>
</div><br/>

Now you can run the following command to render the HTML with request and response body:

newman run <path to your collection json file> -e <path to your environment json file> -r cli,html --reporter-html-template template.hbs

Hope this helps!

like image 142
Mandeep Singh Avatar answered Sep 17 '22 15:09

Mandeep Singh