This is an extension on a previous question I asked.

I am getting some data from an API built on node.js.

I would like to save this data to a csv. The problem I have is that I am getting the data from the API and have verified this (console.log shows this). The csv is also being created but the problem is that nothing is in the csv, it is a blank csv.

This is the code I have written;

```
const boxrec = require("boxrec").Boxrec;
const fastcsv = require('fast-csv');
const fs = require('fs');
async function getCookieJar(){
    try {
        const cookieJar = await boxrec.login('***','******');
        return cookieJar;
    } catch (e) {
        console.log("Login error: " + e);
    }
};
async function writeData() {
    const cookieJar = await getCookieJar();
    var boxers = await boxrec.getPersonById(cookieJar,356831);
    const ws = fs.createWriteStream("C:\\Users\\User\\Documents\\testing2.csv");
    fastcsv
    .write(boxers, {headers: true })
    .pipe(ws);
};
try {
    writeData();
} catch (error) {
    console.log("Error in function " + error);
}

```

Running the code also produces this error message:

> 
> (node:15672) UnhandledPromiseRejectionWarning: Unhandled promise
>  rejection. This error originated either by throwing inside of an async
>  function without a catch block, or by rejecting a promise which was
>  not handled with .catch(). (rejection id: 1)(node:15672) [DEP0018]
>  DeprecationWarning: Unhandled promise rejections are deprecated. In
>  the future, promise rejections that are not handled will terminate the
>  Node.js process with a non-zero exit code.
> 
> 
> 

Update.

I added try, catch to writeData and this is the error message I got:

```
(node:4264) UnhandledPromiseRejectionWarning: TypeError: rows.reduce is not a function
    at Object.exports.write (C:\Users\User\node_modules\fast-csv\build\src\formatter\index.js:20:10)
    at writeData (C:\Users\User\Documents\index.js:17:6)
(node:4264) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4264) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

```

console.log(boxers) returns this:

```
r {
  '$': [Function: initialize] {
    fn: initialize { constructor: [Circular], _originalRoot: [Object] },
    load: [Function],
    html: [Function],
    xml: [Function],
    text: [Function],
    parseHTML: [Function],
    root: [Function],
    contains: [Function],
    merge: [Function],
    _root: {
      type: 'root',
      name: 'root',
      namespace: 'http://www.w3.org/1999/xhtml',
      attribs: [Object: null prototype] {},
      'x-attribsNamespace': [Object: null prototype] {},
      'x-attribsPrefix': [Object: null prototype] {},
      children: [Array],
      parent: null,
      next: null
    },
    _options: {
      withDomLvl1: true,
      normalizeWhitespace: false,
      xml: false,
      decodeEntities: true
    }
  }
}

```