Skip to main content

Hi! I’m looking for some assistance in troubleshooting the custom code I’m trying to write for a trigger I’m setting up. I’ve referenced the Zapier documentation and other posts similar to the situation here, here, and here. The solution for this situation appears to be wrapping the response as an array “n]”, however, that doesn’t seem to be working in my situation. Below is my code and error response. 

 

In the documentation for the API I’m trying to work with, the example request looks like this:

const options = {method: 'GET', headers: {accept: 'application/json'}};

fetch('https://api.portal.scanifly.com/api/v1/designs/63fbc6498b05fa000747513b?access_token=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));

When I run this code on npm.runkit.com/supertest I get the following results:

 

Any thoughts on what I’m missing? Thanks!

Hey @sgee,

I’m going to move this topic into the Developer Discussion forum, where some of our more technical members hang out. That should get some more eyeballs on it :) 


Thanks @nicksimard. I appreciate it!


Hey @sgee 👋

I see you’ve discussed this action with a few members of our Support team - great! 

To recap for the Community - a search is indeed expecting an array of JSON objects and often this can be achieved by wrapping the response as an array, as you tried.

Since you were then receiving an ‘undefined’ error, I’d recommend checking the Monitoring tab, to see what response the GET is returning from that endpoint, before you wrap it in an array. 

Checking the API docs you’ve linked, I also noticed that the projectId is expected in the url path, so in your screenshot, you’d want to edit the url to be

`https://api.portal.scanifly.com/api/v1/designs/${bundle.inputData.projectId}` 

when using Code Mode.  if you haven’t tried that already 😀


Hi @MarinaH, I forgot this question was still open.

Yes, you’re correct about needing to have `projectId` in the URL path. The error message I was receiving was a bit of a red herring.

Below is the correct custom code for my situation.

  
const options = {
url: `https://api.portal.scanifly.com/api/v1/designs/${bundle.inputData.projectId}`,
method: 'GET',
headers: {
'X-ACCESS-TOKEN': bundle.authData.access_token
},
params: {
'access_token': bundle.authData.access_token
}
}

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

 


Reply