I’m working on a Zapier automation that needs to send webhook requests based on array data. The issue I’m facing is that the number of webhooks being sent is way more than expected.
When my array has 4 elements, I get 16 webhook calls instead of 4. With 3 elements, I see 9 calls instead of 3. It seems like the count is getting squared somehow.
Here’s my current implementation:
const dataArray = JSON.parse(inputData.records)
var payload = dataArray;
var requestConfig = {
"url": "WEBHOOK-ENDPOINT.COM",
"method": "POST",
"headers": {'Content-Type': 'application/json'},
"body": JSON.stringify(payload)
};
var allRequests = dataArray.map(createRequestSettings);
function createRequestSettings(item) {
var config = Object.assign({}, requestConfig);
config.data = JSON.stringify(item);
return config;
}
Promise.all(allRequests.map(executeRequest))
.then(function(results){ callback(null, {totalRequests: results});});
function executeRequest(config) {
return fetch(config.url, config)
.then(function(response) {return response.json();});
}
Looking at your code structure, there’s a fundamental issue with how you’re setting up the request configuration. You’re creating config.data in your createRequestSettings function, but then passing the config object to fetch() which expects different property names. The fetch API uses body for the request payload, not data. Your current setup has both body and data properties, which might be causing confusion in how Zapier processes the requests. Try modifying your createRequestSettings function to use config.body = JSON.stringify(item) instead of config.data. Also, remove the initial var payload = dataArray line since you’re not using it effectively. This mismatch between expected and actual request properties could be causing Zapier to interpret your requests incorrectly and trigger multiple executions.
The squaring behavior you’re experiencing is likely caused by nested iteration within your Zapier workflow. This commonly happens when you have a Loop action configured before your webhook step, which then processes each array element individually rather than as a batch. Check if you have any Loop or Iterator actions in your Zap that might be running before this code executes. If your webhook step is placed inside a loop that’s already iterating through your array elements, then your JavaScript code will run once per array element, creating the multiplication effect you’re seeing. To fix this, either remove the Loop action and let your JavaScript handle all the iterations, or restructure your code to send only one webhook per execution if you need to keep the loop for other reasons.
i think you’re right about the redundancy. by assigning payload and then setting config.data, you’re sending extra data. just focus on the config.data part for the right amount of webhooks. good luck!