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:

@pranavdavar not sure if this will help?

Thank you @allenheltondev. 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

Hi Allen,
Thanks for the detailed steps. This was really helpful for my requirement. However, I’m unable to fetch the response from the collection variable. It shows me " 403: You don’t have the permissions to access this API" in the CollectionResponses- Current value field. Could you please help me with this.
Thanks in advance!