-1

Is there any ways to create an excel sheet from the response of a loopback API?

Here is the sample response body

{
  "status": "OK",
  "testSuite": {
    "name": "testsuite2",
    "id": 8,
    "userId": 3
  },
  "testCase": [
    {
      "id": 15,
      "testCaseId": 1
    },
    {
      "id": 16,
      "testCaseId": 4
    }
  ]
}
veenaMSL
  • 101
  • 1
  • 9

1 Answers1

1

First, I would clean up the response object and create a variable with the data I want to write to the excel sheet in a simple structure as the obj variable in my example below. The fastest approach is to use json2xls. The code below can be used as part of your api endpoint which will result in writing an xlsx file in the root folder of your project

    var obj = [
      {
        "id": 15,
        "testCaseId": 1
      },
      {
        "id": 16,
        "testCaseId": 4
      }
    ];

    var fs = require('fs');
    var json2xls = require('json2xls');
    var xls = json2xls(obj);
    fs.writeFileSync('data.xlsx', xls, 'binary');
Numant Santz
  • 170
  • 1
  • 11