Skip to main content
Best answer

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


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 TessaloneBest 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

 

View original
Did this topic help you find an answer to your question?

7 replies

DavidLGS
Forum|alt.badge.img+6
  • Zapier Expert
  • 122 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 Expert
  • 122 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.


gatipe
Forum|alt.badge.img
  • Beginner
  • 13 replies
  • March 14, 2025
Strijdhagen wrote:

I'm trying to create an integration using a Rest API. Afaik the way to do this is using a webhook check it out.
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?

To return all items in the array, ensure that your webhook is set up to handle the full response, not just the first item. Check the API documentation for pagination or response limits. If necessary, modify your webhook logic to loop through the array and handle each item.


Troy Tessalone
Forum|alt.badge.img+14

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
Forum|alt.badge.img+14
  • Zapier Expert
  • 31147 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!


Reply