Best answer

API-KEY works in Form mode but not in Code mode

  • 18 September 2021
  • 2 replies
  • 182 views

Hi I’m Rinaldo 

new in the Zapier developer platform.

I’m facing an issue and need your help Thank you.

the API works correctly in form mode if I try to use the code mode I get the following error

We hit an error adding your new account

authentication failed: Key is not defined What happened (You are seeing this because you are an admin): Executing authentication.test with bundle Key is not defined Console logs: Stack trace: ReferenceError: Key is not defined at eval (eval at makeFunction (/var/task/node_modules/zapier-platform-core/src/tools/schema-tools.js:11:39), <anonymous>:8:38) at execute (/var/task/node_modules/zapier-platform-core/src/execute.js:78:12) at /var/task/node_modules/zapier-platform-core/src/create-command-handler.js:29:20 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 (/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)

 

This the code (no change at the  moment)

const options = {
  url: 'https://nibi2f2m6a.execute-api.us-east-1.amazonaws.com/memento-api/359',
  method: 'GET',
  headers: {
    'X-MERCHANT-ID': bundle.authData.merchantId,
    'X-API-KEY': bundle.authData.Api-Key,
    'X-API-SECRET': bundle.authData.Api-Secret
  },
  params: {
    'Api-Secret': bundle.authData.Api-Secret,
    'merchantId': bundle.authData.merchantId,
    'Api-Key': bundle.authData.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;
  });

my need is to change the url Address in this way

const apiURL = 'https://url.com/api/'+{{bundle.authData.merchantId}}

const options = {

url:’apiURL,

….

But since the standard code is to working I can not test it.

 

Any help please

Best,

Rinaldo 

 

 

 

 

icon

Best answer by Zane 23 September 2021, 23:57

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.

2 replies

Userlevel 7
Badge +9

@Rinaldo Bonazzo : In code mode your names need to be valid JavaScript references. The error message is telling you something is going wrong with something called “Key”. Scanning through your code you see a reference to:

 

bundle.authData.Api-Key

and 

bundle.authData.Api-Secret

Hyphens aren’t legal in JS variable identifiers. So, instead, change all of the references with hyphens to this style of reference:

bundle.authData[‘Api-Key’]

This should get you up and running.

@Zane thanks for helpful answer.

It’s work fine

Regards