Log responses from collection to a file

Is it possible to write all the responses to a file when we run a postmancollection

Kind of, kind of not.

I just answered this question for somebody this morning:

@darkphoenix not sure if this will help?

Thank you @allen.helton. With this implementation, we have to extract all the data from environment variables after running the collection. Then we can save the data by copying it to some text file. The only concern is if we have many requests and copy and pasting will be a bit troublesome.
Is it possible to access the file system from script?

Why will it be troublesome?

Another recommendation I usually make is to just use some API like airtable or Google Sheets to save the value from the environment variable there. That way it’s accessible in the cloud and not just on a single machine.

Thank You for the suggestion :slight_smile:
I have one doubt, the moment I use the snippet which you provided to use. When we call second-time same request and script tries to fetch data from the collection variable, but now the variable gets data in String format, not the array.
How can we make sure the data fetched from variables are typecast to array?

I just had a typo in that solution

let responses = pm.collectionVariables.has('collectionResponses') ? JSON.parse(pm.collectionVariables.get('collectionResponses')) : []; 
responses.push(pm.response.json()); 
pm.collectionVariables.set('collectionResponses', JSON.stringify(responses));
1 Like

Sorry for the late response, it worked :slight_smile:

1 Like