Hello, I made a GET request that gives me a text/csv response. However, i would like to append this to a already existing excel file. Is this possible? Thanks in advance/
Not directly from Postman, but it can work from Newman.
If you know JavaScript, you can write a custom script. I did a tutorial about a similar use-case:
You can not use external files directly in postman other than for data file. But a work around is to use the visualizer function. Add the below code in your test section
//Assuming you have your csv content in the variable csv
csv=JSON.stringify(csv)
a =`
<html>
<body>
<input type="file" id="fileinput" />
<pre id="ReadResult"></pre>
<script type="text/javascript">
function readSingleFile(evt) {
//Retrieve the first (and only!) File from the FileList object
var f = evt.target.files[0];
if (f) {
var r = new FileReader();
r.onload = function (e) {
var contents = e.target.result;
contents = contents + "\\n" + ${csv}
console.log(contents)
const blob = new Blob([contents], { type: 'text/plain' });
const a = document.createElement('a');
a.setAttribute('download', "fileName.csv");
a.setAttribute('href', window.URL.createObjectURL(blob));
a.click()
document.getElementsByTagName("body")[0].appendChild(a);
}
r.readAsText(f);
} else {
alert("Failed to load file");
}
}
document.getElementById('fileinput').addEventListener('change', readSingleFile, false);
</script>
</body>
</html>`
pm.visualizer.set(a)
Now goto visualize tab:
Just upload the csv file you have , this will append the content to that file and ask where to save the file.
Thanks. But you have to manually pick a file and manually save it to your specified location. I was wondering if it was possible to instead make it search for kronos.csv in a pre-specified folder path, append the response body to that file and automatically save/override it in the same place. Thanks in advance
thats the only way of now from postman APP