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


Is this possible ?

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


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

1 Like

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

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.

1 Like

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 +

1 Like

Nice ! Got it working ! Thanks to you both !


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

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}`;

filePath = ${path.join(folderPath, req.body.requestName) +}.${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.

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

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

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

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:

requestName: `${ || request.url}-${}`

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


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?

1 Like

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.url +,

my OS is windows .

@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.

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:

requestName: `${ || request.url}-${}`

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!

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 !!!

1 Like

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 ?

@singhsivcan Is any way to do the same

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