Skip to main content
Best answer

Webhook 'Get' request always returns just the firsts item in an array

  • March 12, 2025
  • 6 replies
  • 92 views

I'm trying to create an integration using a Rest API. Afaik the way to do this is using a webhook.
However, for every API that I test the webhook always returns only the first item in the array.
Is there a way to return all items in the array?

Best answer by Troy Tessalone

@Strijdhagen 

ChatGPT produced this Zap Code step JavaScript to use.

https://zapier.com/apps/code/help

 

 

let url = inputData.Endpoint;

async function perform(inputData) {
try {
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
// Add authentication if needed: 'Authorization': `Bearer ${inputData.api_key}`
}
});

if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}

const rawJson = await response.text(); // Get raw response as text
let parsedData;

try {
parsedData = JSON.parse(rawJson); // Attempt to parse JSON
} catch (parseError) {
parsedData = null; // If parsing fails, return raw JSON only
}

return {
parsedData, // Parsed JSON object (if valid)
rawJson // Raw JSON response as a string
};
} catch (error) {
return { error: error.message };
}
}

return perform(inputData);

 

OUTPUT

 

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

6 replies

DavidLGS
Forum|alt.badge.img+6
  • Zapier Solution Partner
  • 208 replies
  • March 12, 2025

Can you post screenshots of your webhook request and its response?


  • Author
  • Beginner
  • 3 replies
  • March 12, 2025

Hi David, see below.
If you browse to the API you can see an array with multiple entries:
https://api.sampleapis.com/coffee/hot
Whereas zapier only displays the first entry. This happens to every API I test with, not just this one
 

 


DavidLGS
Forum|alt.badge.img+6
  • Zapier Solution Partner
  • 208 replies
  • March 12, 2025

Bizarre. I’m getting the same thing at that endpoint, but with Postman, it returns the full payload. You should reach out to support or post in the troubleshooting forum.

 

Even more bizarre that you say it happens with every single API. I work extensively with webhooks and haven’t had any errors or limitations like this when pinging an account endpoint.


Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • 34032 replies
  • March 15, 2025

Hi ​@Strijdhagen 

It’s likely related to the below from the Zap trigger: Webhook - Retrieve Poll

That is a GET request as a trigger step.

The returned data from the API endpoint has an “id” for each array item.

 


Deduplication Key
Zapier deduplicates the array we see each poll against the id key. If the id key does not exist, you should specify an alternative unique key to deduplicate off of.
If neither are supplied, we fallback to looking for the shortest key with id in it otherwise we will raise an error.

 

 


Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • 34032 replies
  • Answer
  • March 15, 2025

@Strijdhagen 

ChatGPT produced this Zap Code step JavaScript to use.

https://zapier.com/apps/code/help

 

 

let url = inputData.Endpoint;

async function perform(inputData) {
try {
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
// Add authentication if needed: 'Authorization': `Bearer ${inputData.api_key}`
}
});

if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}

const rawJson = await response.text(); // Get raw response as text
let parsedData;

try {
parsedData = JSON.parse(rawJson); // Attempt to parse JSON
} catch (parseError) {
parsedData = null; // If parsing fails, return raw JSON only
}

return {
parsedData, // Parsed JSON object (if valid)
rawJson // Raw JSON response as a string
};
} catch (error) {
return { error: error.message };
}
}

return perform(inputData);

 

OUTPUT

 


  • Author
  • Beginner
  • 3 replies
  • March 15, 2025

Thanos Troy, I appreciate your input and suggestions.
I wish I was able to do it with just a GET request. I’m setting this up for non-technical users and would rather not have them fiddle with code!