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

Hey,

Is this possible ?

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

1 Like

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

@sivcan 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 + Date.now().

1 Like

Nice ! Got it working ! Thanks to you both !

2 Likes

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

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.