CSV Creation in Postman Flow using Microsoft Graph

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:

Here is the code creating that data:

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';
}

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:

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;
}

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

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