# Log responses from collection to a file

**URL:** <https://community.postman.com/t/log-responses-from-collection-to-a-file/19083>\
**Category:** Help Hub\
**Created:** [January 12, 2021, 10:56am UTC](https://community.postman.com/t/log-responses-from-collection-to-a-file/19083 "2021-01-12T10:56:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![pranavdavar](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pranavdavar/32/9152_2.png) [@pranavdavar](https://community.postman.com/u/pranavdavar)\
**Post date:** [January 12, 2021, 10:56am UTC](https://community.postman.com/t/log-responses-from-collection-to-a-file/19083/1 "2021-01-12T10:56:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [January 12, 2021, 12:46pm UTC](https://community.postman.com/t/log-responses-from-collection-to-a-file/19083/2 "2021-01-12T12:46:59Z")

</div>

Kind of, kind of not.

I just answered this question for somebody this morning:

> [@Collection Runner- How we can save response in local computer for documentation](https://community.postman.com/t/collection-runner-how-we-can-save-response-in-local-computer-for-documentation/18968/4):
>
> I agree with @odanylewycz. To make this easy, you can add a test script on your collection so it automatically runs for every request. let responses = pm.collectionVariables.has('collectionResponses') ? pm.collectionVariables.get('collectionResponses') : []; responses.push(pm.response.json()); pm.collectionVariables.set('collectionResponses', JSON.stringify(responses)); When the collection is has completed, you will have every response from every request in that collection run in the collect…

---

<div class="post-metadata">

**Author:** ![JBird20](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@JBird20](https://community.postman.com/u/JBird20)\
**Post date:** [January 19, 2021, 11:14pm UTC](https://community.postman.com/t/log-responses-from-collection-to-a-file/19083/3 "2021-01-19T23:14:29Z")

</div>

@pranavdavar not sure if this will help?

> **[Write Responses To File](https://documenter.getpostman.com/view/3407886/RWgp1fB5)**
>
> This collection makes it easy for users who want to write the response of each request to a file.
> This can be extended to write anything for eg. meta information or value of variables being used.
> 
> 
> This project is using a powerful feature built in...

---

<div class="post-metadata">

**Author:** ![pranavdavar](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pranavdavar/32/9152_2.png) [@pranavdavar](https://community.postman.com/u/pranavdavar)\
**Post date:** [January 22, 2021, 5:43am UTC](https://community.postman.com/t/log-responses-from-collection-to-a-file/19083/4 "2021-01-22T05:43:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [January 22, 2021, 11:45am UTC](https://community.postman.com/t/log-responses-from-collection-to-a-file/19083/5 "2021-01-22T11:45:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pranavdavar](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pranavdavar/32/9152_2.png) [@pranavdavar](https://community.postman.com/u/pranavdavar)\
**Post date:** [January 22, 2021, 3:24pm UTC](https://community.postman.com/t/log-responses-from-collection-to-a-file/19083/6 "2021-01-22T15:24:56Z")

</div>

Thank You for the suggestion 🙂  
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?

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [January 22, 2021, 5:38pm UTC](https://community.postman.com/t/log-responses-from-collection-to-a-file/19083/7 "2021-01-22T17:38:28Z")

</div>

I just had a typo in that solution

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

```

---

<div class="post-metadata">

**Author:** ![pranavdavar](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pranavdavar/32/9152_2.png) [@pranavdavar](https://community.postman.com/u/pranavdavar)\
**Post date:** [February 1, 2021, 1:43pm UTC](https://community.postman.com/t/log-responses-from-collection-to-a-file/19083/8 "2021-02-01T13:43:23Z")

</div>

Sorry for the late response, it worked 🙂

---

<div class="post-metadata">

**Author:** ![PreethiG](https://avatars.discourse-cdn.com/v4/letter/p/51bf81/32.png) [@PreethiG](https://community.postman.com/u/PreethiG)\
**Post date:** [April 28, 2022, 3:04pm UTC](https://community.postman.com/t/log-responses-from-collection-to-a-file/19083/9 "2022-04-28T15:04:37Z")

</div>

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!
