Best answer

Api is not defined What happened: Executing triggers.new_transaction.operation.perform with bundle api is not defined

  • 1 September 2020
  • 3 replies
  • 1488 views

Userlevel 2

Hi There,

I was trying to write an app for an API using the Web editor (not CLI) and when I switch to code mode in the UI, it throws me the below error:

 

Authentication used: API key in header. 

 

api is not defined What happened (You are seeing this because you are an admin): Executing triggers.new_transaction.operation.perform with bundle api is not defined Console logs: Stack trace: ReferenceError: api is not defined at eval

`new_transaction` is the name of my trigger. 

Full stack trace:

Stack trace: ReferenceError: api is not defined at eval (eval at makeFunction (/var/task/node_modules/zapier-platform-core/src/tools/schema-tools.js:7:30), <anonymous>:8:50) at execute (/var/task/node_modules/zapier-platform-core/src/execute.js:78:12) at input (/var/task/node_modules/zapier-platform-core/src/create-command-handler.js:29:14) at Object.beforeMiddleware.then.newInput (/var/task/node_modules/zapier-platform-core/src/middleware.js:90:22) at bound (domain.js:402:14) at Object.runBound (domain.js:415: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:517:31) at Promise._settlePromise (/var/task/node_modules/bluebird/js/release/promise.js:574:18) at Promise._settlePromise0 (/var/task/node_modules/bluebird/js/release/promise.js:619:10) at Promise._settlePromises (/var/task/node_modules/bluebird/js/release/promise.js:699:18) at _drainQueueStep (/var/task/node_modules/bluebird/js/release/async.js:138:12) at _drainQueue (/var/task/node_modules/bluebird/js/release/async.js:131:9) at Async._drainQueues (/var/task/node_modules/bluebird/js/release/async.js:147:5) at Immediate.Async.drainQueues [as _onImmediate] (/var/task/node_modules/bluebird/js/release/async.js:17:14) at runCallback (timers.js:705:18) at tryOnImmediate (timers.js:676:5) at processImmediate (timers.js:658:5) at process.topLevelDomainCallback (domain.js:126:23)

 

The exact same one works perfectly when using the form mode. (It does throw me the response must be array error, which is what I’m trying to fix in the code mode.)

I have tried my best to Google but with no luck. Any help will be appreciated. 

 

icon

Best answer by BugZapper 2 September 2020, 18:41

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

3 replies

Userlevel 7
Badge +10

@BugZapper can you paste the code that shows up when you switch to code mode? (If there is sensitive data replace the value with generic data) 

 

the error is saying that the variable api is not defined. So something in code mode is looking for a variable named api. Or bundle.api or similar. 
 

it’s odd that it would work in form mode but not in code mode so we’d need to see the code to diagnose or trouble shoot the issue. 

Userlevel 2

@PaulKortman Thank you for your response.

Here is my code

const options = {
url: 'http://demo0132496.mockable.io',
method: 'GET',
headers: {
'Accept': 'application/json',
'my-api-key': bundle.authData.my-api-key
},
params: {
'my-api-key': bundle.authData.my-api-key
}
}

return z.request(options)
.then((response) => {
response.throwForStatus();
const results = response.json;

// You can do any parsing you need for results here before returning them

return results;
});

 

I just found out what the issue was, thanks to Zapier support. My API key was named my-api-key which fails to properly convert to code. bundle.authData.my-api-key is an invalid way to access the property. It should have been converted to bundle.authData[‘my-api-key’]

 

Hope this answer will help someone in the future. 

Userlevel 7
Badge +12

Thanks for sharing the solution, @BugZapper!