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

**URL:** <https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377>\
**Category:** Help Hub\
**Created:** [May 9, 2019, 9:49pm UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377 "2019-05-09T21:49:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![p.varin78](https://avatars.discourse-cdn.com/v4/letter/p/85e7bf/32.png) [@p.varin78](https://community.postman.com/u/p.varin78)\
**Post date:** [May 9, 2019, 9:49pm UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/1 "2019-05-09T21:49:18Z")

</div>

Hey,

Is this possible ?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [May 9, 2019, 10:03pm UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/2 "2019-05-09T22:03:29Z")

</div>

This from @singhsivcan might be able to help with this?

> **[sivcan/ResponseToFile-Postman](https://github.com/sivcan/ResponseToFile-Postman)**
>
> This project helps in writing response (or any data) from a postman request to a file - sivcan/ResponseToFile-Postman

---

<div class="post-metadata">

**Author:** ![p.varin78](https://avatars.discourse-cdn.com/v4/letter/p/85e7bf/32.png) [@p.varin78](https://community.postman.com/u/p.varin78)\
**Post date:** [May 9, 2019, 10:25pm UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/3 "2019-05-09T22:25:21Z")

</div>

Thanks ! I tried but only the last response is exported. Not the ones from the previous iterations. Weird… Any idea ?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [May 9, 2019, 10:36pm UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/4 "2019-05-09T22:36:23Z")

</div>

@singhsivcan would be able to help with this but probably not until he’s back online 😁

I think, if I remember, you might need to modify the server code to `append` the response rather than just `write` over the previous response.

---

<div class="post-metadata">

**Author:** ![matt](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/matt/32/2562_2.png) [@matt](https://community.postman.com/u/matt)\
**Post date:** [May 9, 2019, 10:48pm UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/5 "2019-05-09T22:48:18Z")

</div>

The script uses the request name in Postman as the filename for the export. It sounds like you’re iterating over the same request.

As Danny said, you’ll need to edit `script.js` to check for an existing file, and if so append the response.

Alternatively, if you want each response in a separate file, edit the Test script at the collection level so that the request name will be unique each time: you could append a timestamp for example `+ Date.now()`.

---

<div class="post-metadata">

**Author:** ![p.varin78](https://avatars.discourse-cdn.com/v4/letter/p/85e7bf/32.png) [@p.varin78](https://community.postman.com/u/p.varin78)\
**Post date:** [May 9, 2019, 11:15pm UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/6 "2019-05-09T23:15:26Z")

</div>

Nice ! Got it working ! Thanks to you both !

---

<div class="post-metadata">

**Author:** ![matt](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/matt/32/2562_2.png) [@matt](https://community.postman.com/u/matt)\
**Post date:** [May 10, 2019, 5:31pm UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/7 "2019-05-10T17:31:18Z")

</div>

Great! Which route did you go down in the end?

---

<div class="post-metadata">

**Author:** ![BenHadman](https://avatars.discourse-cdn.com/v4/letter/b/c0e974/32.png) [@BenHadman](https://community.postman.com/u/BenHadman)\
**Post date:** [July 11, 2019, 7:24pm UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/8 "2019-07-11T19:24:17Z")

</div>

Just to tie this bit off you can change line 23 of script.js to include the Date to make each response a different file and prevent from overwriting the previous query each time.

```
filePath = `${path.join(folderPath, req.body.requestName)}.${extension}`;

```

to  
filePath = `${path.join(folderPath, req.body.requestName) + Date.now()}.${extension}`;

To add to this I would like to be able to name the file the name of one of the parameters passed in the api call to be able to distinguish which line in the csv collection file marries up to which response in a more robust way than just top to bottom.

---

<div class="post-metadata">

**Author:** ![lucas.kunert](https://avatars.discourse-cdn.com/v4/letter/l/8491ac/32.png) [@lucas.kunert](https://community.postman.com/u/lucas.kunert)\
**Post date:** [October 10, 2019, 10:04pm UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/9 "2019-10-10T22:04:50Z")

</div>

I tried this but I get an error when I run the test:  
TypeError [ERR\_INVALID\_ARG\_TYPE]: The “path” argument must be of type string. Received type undefined

---

<div class="post-metadata">

**Author:** ![emon22](https://avatars.discourse-cdn.com/v4/letter/e/cab0a1/32.png) [@emon22](https://community.postman.com/u/emon22)\
**Post date:** [October 30, 2019, 12:14pm UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/10 "2019-10-30T12:14:43Z")

</div>

I had a similar issue, it looks like the example provided was missing the “comma” bookends. I fixed it now it’s working.

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

---

<div class="post-metadata">

**Author:** ![pravinder](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pravinder/32/3672_2.png) [@pravinder](https://community.postman.com/u/pravinder)\
**Post date:** [January 23, 2020, 12:30pm UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/11 "2020-01-23T12:30:21Z")

</div>

@singhsivcan  
when i run my collection through the runner by passing the input data through the csv file where the iterations are 64. But it ll store only the first iteration response not for all iteration . please suggest where i am wrong .  
Thanks in Advance

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [January 23, 2020, 5:18pm UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/12 "2020-01-23T17:18:39Z")

</div>

Actually the script is just overwriting over the same file again and again.  
What you can do is modify the name of the request being sent to the local server.

Go to Collection \> Edit Collection \> Test Script

Change the requestName property to:

```javascript
requestName: `${request.name || request.url}-${Date.now()}`

```

Now, it’ll be unique for each request and a new file will be created for each request sent and response received.

---

<div class="post-metadata">

**Author:** ![andres](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@andres](https://community.postman.com/u/andres)\
**Post date:** [January 24, 2020, 12:51am UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/13 "2020-01-24T00:51:35Z")

</div>

Works great! Thanks @singhsivcan!!!  
BTW, since I can tell you master this stuff, can you think of a variant to save all the response bodies into the same file with an identifier by other variable? maybe an environment, parameter or variable from the data file?

---

<div class="post-metadata">

**Author:** ![pravinder](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pravinder/32/3672_2.png) [@pravinder](https://community.postman.com/u/pravinder)\
**Post date:** [January 24, 2020, 5:51am UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/14 "2020-01-24T05:51:13Z")

</div>

Hi @ Sivcan  
It still giving me the single request. I started the node script.js also but write the single response .I have added the function as per your opinion ,Below are the same .

requestName: request.name || request.url + Date.now(),

my OS is windows .

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [January 24, 2020, 10:59am UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/15 "2020-01-24T10:59:12Z")

</div>

@andres You’d have to edit the node script, you can write a `append` functionality to the file handling code and while writing to the file, you can add a timestamp along with the request name and then append the entire JSON body to the file.

You can read more about using [fs.appendFile functionality in node](https://nodejs.org/api/fs.html#fs_fs_appendfile_path_data_options_callback).

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [January 24, 2020, 11:01am UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/16 "2020-01-24T11:01:45Z")

</div>

I think you might have incorrectly copied the code that I gave above.

Make sure you’re editing the **Collection** and not the node script. (You don’t need to).

In the collection put the following again:

```auto
requestName: `${request.name || request.url}-${Date.now()}`

```

Notice the ( **`** ) backtick which is helping us achieve string interpolation in javascript.

In case it’s not working, please share your node script + collection script via DM and let’s see!

---

<div class="post-metadata">

**Author:** ![pravinder](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pravinder/32/3672_2.png) [@pravinder](https://community.postman.com/u/pravinder)\
**Post date:** [January 24, 2020, 11:05am UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/17 "2020-01-24T11:05:29Z")

</div>

@singhsivcan  
Its working fine now after doing some changes in code . Actually i was not putting the (`) backtick . Finally i solved my problem with your solution .  
Great Work @singhsivcan !!!

---

<div class="post-metadata">

**Author:** ![pravinder](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pravinder/32/3672_2.png) [@pravinder](https://community.postman.com/u/pravinder)\
**Post date:** [January 29, 2020, 6:18am UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/18 "2020-01-29T06:18:14Z")

</div>

@singhsivcan  
I have one APi request which is going to translate the text in to speech . Is any way to download the response in an audio format.  
i am able to do it through postman button send and download for single single request .Is any way for a collection of request so that my audio file ll be download ?  
Thanks

---

<div class="post-metadata">

**Author:** ![pravinder](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pravinder/32/3672_2.png) [@pravinder](https://community.postman.com/u/pravinder)\
**Post date:** [February 6, 2020, 6:06am UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/19 "2020-02-06T06:06:38Z")

</div>

@singhsivcan Is any way to do the same

---

<div class="post-metadata">

**Author:** ![3232963](https://avatars.discourse-cdn.com/v4/letter/3/e47774/32.png) [@3232963](https://community.postman.com/u/3232963)\
**Post date:** [August 23, 2020, 8:23pm UTC](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377/20 "2020-08-23T20:23:30Z")

</div>

i have a csv file which i need to test i want to add the response to the line it just finished iterating any way to do this  
thank in advance

[Next page](https://community.postman.com/t/how-to-export-download-response-body-into-an-external-file-from-collection-runner-results/5377.md?page=2)
