如何将邮递员的回复导出到清晰的 laid-out csv/xls 文件?

How do I export a response on postman to a clearly laid-out csv/xls file?

我是 API 的新手,目前正在从事一个项目来分析求职网站 reed.co.uk 的数据。我正在尝试将数据导出到电子表格,变量名称为 headers,而不是 json。典型的 GET 请求,例如

curl --location --request GET 'https://www.reed.co.uk/api/1.0/search?keywords=accountant&location=london' \

Returns这个:

"results": [
    {
        "jobId": 44137966,
        "employerId": 575264,
        "employerName": "REED",
        "employerProfileId": null,
        "employerProfileName": null,
        "jobTitle": "Management Accountant",
        "locationName": "Maidstone",
        "minimumSalary": 28000.00,
        "maximumSalary": 35000.00,
        "currency": "GBP",
        "expirationDate": "28/10/2021",
        "date": "21/09/2021",
        "jobDescription": " My client is looking to recruit an ambitious and commercially aware Management Accountant.  Working closely with the Finance Director, you will provide accurate and timely management accounting information and reports in accordance with strict deadlines.   In addition, you will work closely with the finance team providing support on a daily basis. Please note:  The standard hours of work are 7.00am to 3.45pm, Mo... ",
        "applications": 3,
        "jobUrl": "https://www.reed.co.uk/jobs/management-accountant/44137966"

等等等等

如果我随后按照 Postman 自己的方法写入 csv (https://documenter.getpostman.com/view/3407886/RWgp1fB5?version=latest),生成的文件只包含包含所有数据的一行 - 如果我使用 xls 而不是将其全部放入单个单元格中.理想情况下,每一列都包含工作变量(如果这是正确的术语),例如JobId, employerId, employerName 等,每一行都是一个新的职位条目。

Reed 的 API 文档在此处:https://www.reed.co.uk/developers/jobseeker

提前致谢。

我不想修复现有的api,所以我写了一个新的

步骤 1:安装 json-2-csv

npm install json-2-csv

步骤 2:将以下代码添加到文件 script.js

const converter = require("json-2-csv");

app.post("/toCsv", (req, res) => {
    let filename = `File_${Date.now()}`,
        filePath = `${path.join(folderPath, filename)}.csv`;

    converter.json2csv(req.body, (err, csv) => {
        fs.writeFileSync(filePath, csv);
        if (err) {
            console.log(err);
            res.send("Error");
        } else {
            res.send("Success");
        }
    });
});

步骤 3:启动本地应用程序

node .\script.js

第 4 步:在选项卡 Tests.

内的邮递员中提出请求
const list = pm.response.json().results;

const postRequest = {
  url: 'http://localhost:3000/toCsv',
  method: 'POST',
  header: {
    'Content-Type': 'application/json',
  },
  body: {
    mode: 'raw',
    raw: JSON.stringify(list)
  }
};
pm.sendRequest(postRequest, (error, response) => {
  console.log(error ? error : response);
});

步骤 5: 检查文件夹 Responses