Skip to main content

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

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 (d{"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 (d{"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!

dashes aren’t legal in JavaScript identifiers. Try changing 

 

bundle.authData.X-API-TOKEN

 

to 

 

bundle.authDatau'X-API-TOKEN']


And also, rather than returning 

 

return rresults];

 

You probably want

 

return results.vouches;

 

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


Thank you @Zane.  Really appreciate your help!


Hi there,

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

 

dashes aren’t legal in JavaScript identifiers. Try changing 

 

bundle.authData.X-API-TOKEN

to 

bundle.authDataa'X-API-TOKEN']

 

And also, rather than returning 

 

return cresults];

You probably want

return results.vouches;

 

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