如何在Zapier CLI中使用post_poll方法 [英] How to use the post_poll method in Zapier CLI

查看:106
本文介绍了如何在Zapier CLI中使用post_poll方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

According to the docs, I should use a post_poll function to add the missing id field in the response.

如何添加post_poll函数?

How do I add the post_poll function ?

这是我的错误:

结果必须是一个数组,具有:对象, ({"totalevents":83,"events":[{"eventid":10266033,"c) -得到的结果缺少"id"属性(83)

Results must be an array, got: object, ({"totalevents":83,"events":[{"eventid":10266033,"c) - Got a result missing the "id" property (83)

尝试过,但我不清楚,我是Zapier-CLI的新手

Tried following this but it is not clear to me, I'm very new to 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);
            });
};

示例响应如下,为了避免在zapier test|push时出错,我手动添加了id参数:

The sample response is the following, with the distiction that I added the id param manually to avoid errors when 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)中创建的应用程序中使用,并且工作正常:

The ACTUAL response from the endpoint the following which is used in the app created in the Web Builder App instead of CLI and works fine:

{
    "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
}

我在考虑以下内容,但是我该如何注册?

I was thinking something along the line of the following, but how do I register this ?

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;

推荐答案

很好,所以您快到了! CLI应用程序没有pre_post_轮询方法.相反,您可以在响应进入后进行任何操作.

Nice, so you're almost there! CLI apps don't have pre_ and post_ poll methods. Instead, you put any manipulation after the response comes in.

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
            }) 
        })
};

这篇关于如何在Zapier CLI中使用post_poll方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆