# CSV Creation in Postman Flow using Microsoft Graph

**URL:** <https://community.postman.com/t/csv-creation-in-postman-flow-using-microsoft-graph/64232>\
**Category:** Help Hub\
**Tags:** csv, postman-flows\
**Created:** [July 17, 2024, 8:30pm UTC](https://community.postman.com/t/csv-creation-in-postman-flow-using-microsoft-graph/64232 "2024-07-17T20:30:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![legiuffre](https://avatars.discourse-cdn.com/v4/letter/l/b9e5f3/32.png) [@legiuffre](https://community.postman.com/u/legiuffre)\
**Post date:** [July 17, 2024, 8:30pm UTC](https://community.postman.com/t/csv-creation-in-postman-flow-using-microsoft-graph/64232/1 "2024-07-17T20:30:25Z")

</div>

Hello community

I feel this is a simple fix but I have been going around in circles and do not want to use up all our Flow credits. I am trying to create a CSV file using a Postman Flow. It is passing the data through but not creating a new line for each CSV line created.

Here is the request in the log:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/a/9/a97aaad2770f71e12ede31a56249e23c9756e6ed.png)

Here is the code creating that data:

```auto
function convertToCSV(objArray: any[], columns: string[]): string {
  const array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
  let str = '';
  let row = '';

  str = "VIN,Date,Memo,Amount,Type\r\n";

for (let i = 0; i < array.length; i++) {
  let line = '';
  for (let index of columns) {
    if (index === 'custcol1') {
      truckVIN = array[i][index];
    }
    if (line !== '') line += ',';
    line += array[i][index] || ''; 
  }
  str += line + '\r\n';
}

```

---

<div class="post-metadata">

**Author:** ![flows-daniel](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/flows-daniel/32/25516_2.png) [@flows-daniel](https://community.postman.com/u/flows-daniel)\
**Post date:** [July 17, 2024, 10:20pm UTC](https://community.postman.com/t/csv-creation-in-postman-flow-using-microsoft-graph/64232/2 "2024-07-17T22:20:59Z")

</div>

Hi @legiuffre

I couldn’t get the function you wrote to execute in the Evaluate Block as is, but I re-wrote it slightly and this seemed to work:

```auto
function convertToCSV(objArray: any[], columns: string[]): string {
  const array = typeof objArray !== 'object' ? JSON.parse(objArray) : objArray;
  let csvString = 'VIN,Date,Memo,Amount,Type\r\n'; // Adding the header row

  for (let i = 0; i < array.length; i++) {
    let line = '';
    for (let j = 0; j < columns.length; j++) {
      if (j > 0) line += ','; // Adding a comma before each column except the first one
      const value = array[i][columns[j]] || ''; // Fallback to empty string if value is undefined
      line += value;
    }
    csvString += line + '\r\n'; // Adding a newline at the end of each row
  }

  return csvString;
}

```

 ![Screenshot 2024-07-17 at 3.03.33 PM](https://us1.discourse-cdn.com/getpostman/original/3X/0/8/089af7e2089709e410d613fac59c149296b9663b.png)

If this is still giving you problems, it may be some nuance with the API instead. Happy to jump on a call to debug.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [August 16, 2024, 10:21pm UTC](https://community.postman.com/t/csv-creation-in-postman-flow-using-microsoft-graph/64232/3 "2024-08-16T22:21:43Z")

</div>

Closed on August 16, 2024, 10:21pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
