node.jsautomationzapierzapier-cli

Got a non-object result, expected an object from create Zapier?


I am getting the buffer by request module of NPM & from that buffer i am parsing the pdf with another module pdf-parse. While executing the zap i am getting the error as:

Unhandled error: CheckError: Invalid API Response: - Got a non-object result, expected an object from create ()

Below is my code for action

var utils = require('../utils/utils.js')
const pdf = require('pdf-parse');
var isMetaData = false;
var request = require('request').defaults({ encoding: null });
let a = {}

const register = (z, bundle) => {
    var url = bundle.inputData.value
    getMetaData(url, z).then((a) => {
        return a
    });
    z.console.log("Process started")

};


function getMetaData(url, z) {
    z.console.log("In getmetadata");

    return new Promise((resolve, reject) => {
        request({ url, encoding: null }, (err, resp, buffer) => {
            z.console.log("In request response");

            pdf(buffer).then(function (data) {
                var mdata = data.metadata;
                var filtered = {}
                for (key in mdata._metadata) {
                    if (key.match(/^pdfx:blockchain/)) filtered[key] = mdata[key];
                }
                if (Object.keys(filtered).length === 1) {
                    isMetaData = true
                }
                a.isMetaData = isMetaData
                resolve(a);
                z.console.log("a value set");
            });
        });
    });
}

Logs for Zap:

- - - - - - - - - - - - - - - - - - 

== Log
Process started
== Version
0.1.6
== Step
50c914b6-03be-49ee-bd94-469e81811578
== Timestamp
2019-08-18T06:13:49-05:00

 - - - - - - - - - - - - - - - - - - 

== Log
In getmetadata
== Version
0.1.6
== Step
50c914b6-03be-49ee-bd94-469e81811578
== Timestamp
2019-08-18T06:13:49-05:00

 - - - - - - - - - - - - - - - - - - 

== Log
Unhandled error: CheckError: Invalid API Response:
  - Got a non-object result, expected an object from create ()
What happened:
  Executing creates.register.operation.perform with bundle
  Invalid API Response:
  - Got a non-object result, expected an object from create ()
CheckError: Invalid API Response:
  - Got a non-object result, expected an object from create ()
    at checkOutput (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/app-middlewares/after/checks.js:37:15)
    at Object.collector.then.newOutput (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/middleware.js:80:37)
    at bound (domain.js:301:14)
    at Object.runBound (domain.js:314:12)
    at Object.tryCatcher (:censored:9:d1ba0cf2aa:/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (:censored:9:d1ba0cf2aa:/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (:censored:9:d1ba0cf2aa:/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromiseCtx (:censored:9:d1ba0cf2aa:/node_modules/bluebird/js/release/promise.js:606:10)
    at Async._drainQueue (:censored:9:d1ba0cf2aa:/node_modules/bluebird/js/release/async.js:138:12)
    at Async._drainQueues (:censored:9:d1ba0cf2aa:/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (:censored:9:d1ba0cf2aa:/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)
== Version
0.1.6
== Step
sdf-03be-49ee-bd94-463481811578
== Timestamp
2019-08-18T06:13:49-05:00

 - - - - - - - - - - - - - - - - - - 

== Log
In request response
== Version
0.1.6
== Step
ddwrr345e-sad-49ee-bd94-fsd34535
== Timestamp
2019-08-18T06:13:49-05:00

Solution

  • David here, from the Zapier Platform team.

    Your perform function needs to return a JS object (something wrapped in {}). To make the error go away, ensure your promise returns something.

    The easiest way is the following:

    return new Promise((resolve, reject) => {
      request({ url, encoding: null }, (err, resp, buffer) => {
                // ...
    }).then(myPdf => {
      return {pdf: myPdf} // <-- an object
    })
    

    That said, I'm not sure the code as written will make the file available in later steps as a file object. I'd look into the docs at https://zapier.github.io/zapier-platform/#stashing-files