Hi everyone, I’m a JS noob and I’m building out a trigger to list items from my API, but I’m getting the following error:
Invalid API Response:
- Results must be an array, got: undefined, (undefined)
What happened (You are seeing this because you are an admin):
Executing triggers.Blog_Posts_Listed.operation.perform with bundle
Invalid API Response:
- Results must be an array, got: undefined, (undefined)
Console logs:
Stack trace:
CheckError: Invalid API Response:
- Results must be an array, got: undefined, (undefined)
at checkOutput (/var/task/node_modules/zapier-platform-core/src/app-middlewares/after/checks.js:42:15)
at Object.<anonymous> (/var/task/node_modules/zapier-platform-core/src/middleware.js:80:37)
at bound (domain.js:421:15)
at Object.runBound (domain.js:432:12)
at Object.tryCatcher (/var/task/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/var/task/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/var/task/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromiseCtx (/var/task/node_modules/bluebird/js/release/promise.js:641:10)
at _drainQueueStep (/var/task/node_modules/bluebird/js/release/async.js:97:12)
at _drainQueue (/var/task/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/var/task/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues Qas _onImmediate] (/var/task/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (internal/timers.js:464:21)
at process.topLevelDomainCallback (domain.js:152:15)
at process.callbackTrampoline (internal/async_hooks.js:128:24)
Here’s my code:
const options = {
url: 'https://app.quickblog.co/api/v1/listposts',
method: 'POST',
headers: {
'accept': 'application/json',
'token': bundle.authData.token,
'apikey': bundle.authData.apikey,
'apisecretkey': bundle.authData.apisecretkey
},
params: {
'page': bundle.meta.page
},
body: {
'accountId': bundle.inputData.accountId
}
}
return z.request(options)
.then((response) => {
response.throwForStatus();
const results = response.json.data;
results.forEach(function(result) {
result.originalId = result.id;
});
return results.data;
});
Support have already helped me loads and I can’t keep going back to them to help me fix my code! Any ideas how I can fix this? I believed the results.data statement already accounted for the array presentation but I can’t work out what I’m doing wrong here! Any help would be much appreciated!