【问题标题】:JSON append response with attribute from link带有来自链接的属性的 JSON 附加响应
【发布时间】:2020-05-07 06:20:30
【问题描述】:

我在 Zapier 有 API 端点,我从工资系统调用所有已批准的休假请求。作为数据。

    const options = {
  url: 'https://api.somepayroll.com/api/v1/leaves/requests',
  method: 'GET',
  headers: {
    'Accept': 'application/json',
    'Authorization': `Bearer ${bundle.authData.access_token}`,
    'X-CLIENT-SECRET': bundle.authData.client_secret,
    'X-CLIENT-ID': bundle.authData.client_id,
    'X-STATUS': bundle.inputData.status
  },
  params: {

  }
}

return z.request(options)
  .then((response) => {
    response.throwForStatus();
    const results = z.JSON.parse(response.content);

    // You can do any parsing you need for results here before returning them

    return results.content;
  });

这让我得到以下回应:

[
  {
    "employeeId": "1",
    "requestId": 5487,
    "hours": 8,
    "leaveFromDate": "19-Feb-2020",
    "leaveToDate": "19-Feb-2020",
    "reason": "Birthday Party",
    "status": "Pending",
    "payElement": "Annual Leave",
    "leaveBalanceType": {
      "leaveType": "Annual",
      "name": "Annual Leave",
      "unit": "hours",
      "organisationSpecific": false
    },
    "payElementId": 50,
    "daysConsumed": 0,
    "daysCurrent": 0,
    "daysRemaining": 0,
    "quantityConsumed": 0,
    "quantityCurrent": 0,
    "quantityRemaining": 8,
    "additionalApprovalAcquired": false,
    "leaveInDays": false,
    "links": [
      {
        "rel": "self",
        "href": "https://api.somepayroll.com/api/v1/leaves/requests/5487"
      },
      {
        "rel": "employee",
        "href": "https://api.somepayroll.com/api/v1/employees/1"
      },
      {
        "rel": "payelement",
        "href": "https://api.somepayroll.com/api/v1/payelements/AL"
      }
    ],
    "id": "5487"
  },
  {
    "employeeId": "1",
    "requestId": 5551,
    "hours": 8,
    "leaveFromDate": "23-Jan-2020",
    "leaveToDate": "23-Jan-2020",
    "reason": "Camping",
    "status": "Pending",
    "payElement": "Annual Leave",
    "leaveBalanceType": {
      "leaveType": "Annual",
      "name": "Annual Leave",
      "unit": "hours",
      "organisationSpecific": false
    },
    "payElementId": 50,
    "daysConsumed": 0,
    "daysCurrent": 0,
    "daysRemaining": 0,
    "quantityConsumed": 0,
    "quantityCurrent": 0,
    "quantityRemaining": 8,
    "additionalApprovalAcquired": false,
    "leaveInDays": false,
    "links": [
      {
        "rel": "self",
        "href": "https://api.somepayroll.com/api/v1/leaves/requests/5551"
      },
      {
        "rel": "employee",
        "href": "https://api.somepayroll.com/api/v1/employees/1"
      },
      {
        "rel": "payelement",
        "href": "https://api.somepayroll.com/api/v1/payelements/AL"
      }
    ],
    "id": "5551"
  }
]

我想做的也是从回复https://api.somepayroll.com/api/v1/employees/1 中的链接中获取员工的姓名,因为它只给了我身份证号码。是否可以像这样交叉链接数据并匹配employeeID 并让名为firstName 的数据成为此结果的一部分?

【问题讨论】:

    标签: javascript arrays json rest zapier


    【解决方案1】:

    它应该由后端处理,但是您可以从响应中调用链接并获取额外数据,

    【讨论】:

    猜你喜欢
    • 2016-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-05
    • 1970-01-01
    • 2021-01-08
    • 2019-04-19
    相关资源
    最近更新 更多