Skip to main content
Best answer

'API is not defined' in Code mode, 'Invalid API Response' in Form mode

  • November 4, 2021
  • 4 replies
  • 284 views

Not sure what I’m doing wrong, but I’m unable to correctly Poll an API endpoint when setting up a trigger on the Zapier Platform.


In Code Mode, I’ve put the following:

const options = {
  url: 'https://api.vouchfor.com/v1/vouches',
  method: 'GET',
  headers: {
    'X-Api-Key': bundle.authData.X-API-TOKEN
  },
  params: { 
  },
}

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

Whilst in Form Mode I’ve put:

 

The response I’m getting is:

Code Mode

API is not defined
What happened (You are seeing this because you are an admin):
  Executing triggers.new_vouch.operation.perform with bundle
  API is not defined

Form Mode

Invalid API Response:
  - Results must be an array, got: object, ({"vouches":[{"id":"vWqCoyHzAA","status":"RESPONDED)
  - Got a result missing the "id" property ([{"id":"vWqCoyHzAA","status":"RESPONDED","url":"https://app.vouchfor.com/vWqCoyHzAA"},{"id":"2Yk92vHCUg","status":"OPENED","url":"https://app.vouchfor.com/request/2Yk92vHCUg"},{"id":"auxP1iDLfF","status":"RESPONDED","url":"https://app.vouchfor.com/au)
What happened (You are seeing this because you are an admin):
  Executing triggers.new_vouch.operation.perform with bundle
  Invalid API Response:
  - Results must be an array, got: object, ({"vouches":[{"id":"vWqCoyHzAA","status":"RESPONDED)
  - Got a result missing the "id" property ([{"id":"vWqCoyHzAA","status":"RESPONDED","url":"https://app.vouchfor.com/vWqCoyHzAA"},{"id":"2Yk92vHCUg","status":"OPENED","url":"https://app.vouchfor.com/request/2Yk92vHCUg"},{"id":"auxP1iDLfF","status":"RESPONDED","url":"https://app.vouchfor.com/au)

 

What Zapier returns tin the HTTP response content / what I get in say Postman:

{
  "vouches": [
    {
      "id": "vWqCoyHzAA",
      "status": "RESPONDED",
      "url": "https://app.vouchfor.com/vWqCoyHzAA"
    },
    {
      "id": "2Yk92vHCUg",
      "status": "OPENED",
      "url": "https://app.vouchfor.com/request/2Yk92vHCUg"
    }...

 

I’ve tried a few different tweaks with the code, however I am having no luck.  Any help anyone can provide would be greatly appreciated!

Best answer by christina.dBest answer by christina.d

Hi there,

I wanted to pop in and consolidate Zane’s replies down into one reply for anyone following along:

 

Zane wrote:

dashes aren’t legal in JavaScript identifiers. Try changing 

 

bundle.authData.X-API-TOKEN

to 

bundle.authData['X-API-TOKEN']

 

Zane wrote:

And also, rather than returning 

 

return [results];

You probably want

return results.vouches;

 

As that’s actually the array that contains your items.

 

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

4 replies

Forum|alt.badge.img+9
  • Zapier Staff
  • 331 replies
  • November 4, 2021

dashes aren’t legal in JavaScript identifiers. Try changing 

 

bundle.authData.X-API-TOKEN

 

to 

 

bundle.authData['X-API-TOKEN']


Forum|alt.badge.img+9
  • Zapier Staff
  • 331 replies
  • November 4, 2021

And also, rather than returning 

 

return [results];

 

You probably want

 

return results.vouches;

 

As that’s actually the array that contains your items.


  • Author
  • Beginner
  • 1 reply
  • November 4, 2021

Thank you @Zane.  Really appreciate your help!


christina.d
Forum|alt.badge.img+9
  • Zapier Staff
  • 2653 replies
  • Answer
  • January 25, 2022

Hi there,

I wanted to pop in and consolidate Zane’s replies down into one reply for anyone following along:

 

Zane wrote:

dashes aren’t legal in JavaScript identifiers. Try changing 

 

bundle.authData.X-API-TOKEN

to 

bundle.authData['X-API-TOKEN']

 

Zane wrote:

And also, rather than returning 

 

return [results];

You probably want

return results.vouches;

 

As that’s actually the array that contains your items.