如何在Zapier CLI

时间:2017-12-15 17:47:44

标签: zapier-cli

根据docs,我应该使用post_poll函数在响应中添加缺少的id字段。

如何添加post_poll功能?

这是我的错误:

  

结果必须是数组,得到:对象,   ({" totalevents":83,"事件":[{"事件ID":10266033," c)中      - 得到的结果错过了" id"财产(83)

尝试跟随this,但我不清楚,我对Zapier-CLI非常陌生

更新 - 添加代码

这是返回数据的函数:

const listEvents = (z, bundle) => {

    console.log('listing events.. ');
    let client_id = bundle.inputData.client_id;
    const requestOpts = {
        url: `https://wccqa.on24.com/wcc/api/v2/client/${client_id}/event`  
    };

    return z.request(requestOpts)
            .then((response) => {
                return z.JSON.parse(response.content);
            });
};

示例回复如下,我怀疑我手动添加id参数以避免zapier test|push时出错:

{
    "id": 9964513,
    "eventid": 9964513,
    "archivestart": "2017-09-21T10:30:00-07:00",
    "archiveend": "2018-09-21T10:30:00-07:00",
    "description": "Zapier Event Test",
    "iseliteexpired": "N",
    "displaytimezonecd": "America/Bogota",
    "eventtype": "Live Webcam ",
    "regrequired": true,
    "clientid": 22921,
    "liveend": "2017-09-21T10:00:00-07:00",
    "createtimestamp": "2017-09-21T09:47:44-07:00",
    "audienceurl": "https://localhost.on24.com/wcc/r/9964513/C49755A02229BD48E6010848D7C81EF8",
    "lastmodified": "2017-09-21T09:47:44-07:00",
    "livestart": "2017-09-21T08:45:00-07:00",
    "goodafter": "2017-09-21T09:00:00-07:00",
    "regnotificationrequired": true,
    "isactive": true,
    "localelanguagecd": "en"
}

来自端点的 ACTUAL 响应以下是在Web Builder App中创建的应用程序中使用的,而不是CLI,并且工作正常:

{
    "events": [
        {
            "eventid": 9964513,
            "archivestart": "2017-09-21T10:30:00-07:00",
            "archiveend": "2018-09-21T10:30:00-07:00",
            "description": "Zapier Event Test",
            "iseliteexpired": "N",
            "displaytimezonecd": "America/Bogota",
            "eventtype": "Live Webcam ",
            "regrequired": true,
            "clientid": 22921,
            "liveend": "2017-09-21T10:00:00-07:00",
            "createtimestamp": "2017-09-21T09:47:44-07:00",
            "audienceurl": "https://localhost.on24.com/wcc/r/9964513/C49755A02229BD48E6010848D7C81EF8",
            "lastmodified": "2017-09-21T09:47:44-07:00",
            "livestart": "2017-09-21T08:45:00-07:00",
            "goodafter": "2017-09-21T09:00:00-07:00",
            "regnotificationrequired": true,
            "isactive": true,
            "localelanguagecd": "en"
        }
    ],
    "totalevents": 1
}

我正在考虑下面的内容,但我该如何注册呢?

const postPoll = (event,z,bundle) => {

    if(event.key === 'events'){

        var results = z.JSON.parse(bundle.request.data).results;

        var events = results.events.map(function(event){
                              event.id = event.eventid;
                              return event;
                            });     

        bundle.request.data = events;
    }
};

module.exports = postPoll;

1 个答案:

答案 0 :(得分:3)

很好,所以你几乎就到了! CLI应用程序没有pre_post_轮询方法。相反,你会在响应进来之后进行任何操作。

const listEvents = (z, bundle) => {
console.log('listing events.. ');
let client_id = bundle.inputData.client_id;
const requestOpts = {
    url: `https://wccqa.on24.com/wcc/api/v2/client/${client_id}/event`  
};

return z.request(requestOpts)
        .then((response) => {
            return z.JSON.parse(response.content);
        })
        .then(data => {
            const events = data.events; // array of events
            return events.map(function(e){ // returns array of objects with `id` defined
                e.id = e.event_id
                return e
            }) 
        })
};