【问题标题】:Zapier Results from `triggers.new_booking.operation.perform` must be an array of objects来自`triggers.new_booking.operation.perform` 的 Zapier 结果必须是对象数组
【发布时间】:2019-10-27 21:45:59
【问题描述】:

我正在为一个应用构建一个 zapier 集成。应用会返回这样的 JSON 响应...

{
  result: "Success",
  message: "Showing a total of 1 bookings",
  bookings: {
    42: {
      event: {
        event_name: "Chris's Event",
        event_date_uk: "Saturday 22nd Jun 2019"
      }
    }
  }
}

在我的 zapier 解析器中,我有以下内容....

const options = {
  url: bundle.authData.url+`/api/v1/bookings`,
  method: 'GET',
  headers: {
    'Accept': 'application/json'
  },
  params: {
    'key': bundle.authData.api_key,
    'secret': bundle.authData.client_secret,
    'booking_id': 42,
    'scope': 'full'
  },
}

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

    return results["bookings"];

  });

但是,当我测试时,我得到以下内容......

triggers.new_booking.operation.perform 的结果必须是对象数组。我们得到了{"42": {"event": {"event_name": "Chris's Event", "event_date_uk": "Saturday 22nd Jun 2019"}}}

我认为 JSON.parse 确实返回了一个对象?从我所见,我返回了一个对象数组。任何想法我做错了什么?

【问题讨论】:

    标签: javascript zapier


    【解决方案1】:

    这包含一个对象(预订)的数组

    {
      "result": "Success",
      "message": "Showing a total of 1 bookings",
      "bookings": [
        {
          "42": {
            "event": {
              "event_name": "Chris's Event",
              "event_date_uk": "Saturday 22nd Jun 2019"
            }
          }
        }
      ]
    }
    

    编辑:要访问 JSON 中的事件属性,它是 bookings.42.event,在上面的 JSON 中是 bookings[0].42.event

    【讨论】:

    • 但我只返回预订...返回结果["bookings"];错误是说我应该返回一个对象数组,这是我在做什么?
    • 没有。您的 JSON 没有任何预订数组。
    • smh。谢谢你。是时候再来一杯咖啡了!
    • const result = Object.values(results["bookings"]) 已排序
    • 很高兴为您提供帮助
    猜你喜欢
    • 2019-12-16
    • 2020-10-09
    • 2019-12-23
    • 2021-05-06
    • 2020-11-14
    • 1970-01-01
    • 1970-01-01
    • 2019-09-21
    • 1970-01-01
    相关资源
    最近更新 更多