How to save request & response result as a file?

Is there any way to save all the response & response raw as a file ? Because i need to record every entry the postman had sended.

@dugufei This should help: http://blog.getpostman.com/2017/09/01/write-to-your-local-file-system-using-a-postman-collection/

2 Likes

For future visitors:

As an alternative, you can use this collection that explains how you can write any data from Postman to a file (includes support for JSON, CSV and other file extensions as required):
Write Responses to File (fork it and read the docs to get started)
It also includes a server to help users get started.

4 Likes

I want to use collection with data, responses from request will be a binary files. Is there way to point in which folder downloaded files should be saved?
If it isn’t possible directly in Postman app, can “Write Responses To File” solution(mentioned in above post) can be adjusted to download binary files?

@singhsivcan can you(or anyone from Postman team) confirm that there is no way to point in which folder downloaded files should be saved, when request(which downloads binnary data) is send in runing collection(with data)?

Dear @singhsivcan,
I want to save the bitstream of pdf file that responses from a request. When I call the request and click the save response menu on the UI the file is saved. So the request is working fine.
I added the test script to my collection. It is works as you described. So there is no problem with the script and setup.
Than I moved the script to the exact request that I want to save the response and changed the fileextension to pdf as below.

let dataToFile = {
        requestName: request.name || request.url,
        fileExtension: 'pdf',
        responseData: pm.response.text()
    };
    pm.sendRequest({
        url: 'http://localhost:3000/write',
        method: 'POST',
        header: 'Content-Type:application/pdf',
        body: {
            mode: 'raw',
            raw: JSON.stringify(dataToFile)
        }
    }, function(err, res) {
        console.log(res);
    });

The posman console reply as internal server error as below:

{id: "6fb5ca89-a49b-479f-b30d-bb4855966226", status: "Internal Server Error", code: 500…}
    id: "6fb5ca89-a49b-479f-b30d-bb4855966226"
    status: "Internal Server Error"
    code: 500
    header: [7]
    stream: {…}
    cookie: [0]
    responseTime: 2079
    responseSize: 1380

What am I missing? Do you have guess?

Try this:

var NAme= jsonData.References

                // The opts for the server, also includes the data to be written to file
                let opts = {
                    requestName: (request.name || request.url) +" "+ NOpmbre,
                    fileExtension: 'json',
                    mode: 'writeFile', // Change this to any function of the fs library of node to use it.
                //   uniqueIdentifier: false,
                    responseData: pm.response.text()
                };

                pm.sendRequest({
                    url: 'http://localhost:3000/write',
                    method: 'POST',
                    header: 'Content-Type:application/json',
                    body: {
                        mode: 'raw',
                        raw: JSON.stringify(opts)
                    }
                }, function (err, res) {
                    console.log(res);
                });