1

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

How do I add the post_poll function ?

Here's my error:

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

Tried following this but it is not clear to me, I'm very new to Zapier-CLI

Update - adding code

This is the function that returns the data:

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

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

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;
Esteban Rincon
  • 2,040
  • 3
  • 27
  • 44

1 Answers1

3

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
            }) 
        })
};
xavdid
  • 5,092
  • 3
  • 20
  • 32
  • Excelent! Thank you very much. Sorry to bother so much but, how do I solve the following error when running `zapier test` locally ? `Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves` – Esteban Rincon Dec 15 '17 at 20:26
  • hard to tell for sure without seeing the code, but make sure you return the `AppTester` call or write more explicit tests and call `done()`, like the message says. See [the docs](https://github.com/zapier/zapier-platform-cli#writing-unit-tests). – xavdid Dec 15 '17 at 23:17
  • I'll create a new question and pass the link jejej – Esteban Rincon Dec 15 '17 at 23:22