Question:
I’m trying to call upon a function I created in the back end with a http-functions.web.js but when I try to test it out in the live site I get this in the devconsole
“TypeError: (0 , e.sendDataToZapier) is not a function
at eval (”
Product:
Wix Editor
What are you trying to achieve:
I have a back end code which I want to send CMS data to a Zapier webhook so I can use it for a mailing list
What have you already tried:
I’ve googled and tried to make sure all formatting and syntax is correct but the front end cant seem to call upon the backend even for me to test if the backend code is working. I tried the sample “multiply” function and that returned correctly but the one for sending data to zapier isnt seem to be calling.
Additional information:
I’m very new to coding in java script and I will admit I use GPT to help me build the code. Im reading books to understand more about javascript at same time so its kind of a learning in process for me. Thank you!
the import code
import { sendDataToZapier } from 'backend/http-functions.web.js';
$w.onReady(() => {
console.log("🚀 Site is ready! Sending events to Zapier...");
sendDataToZapier()
.then(response => console.log("✅ Events successfully sent to Zapier:", response))
.catch(error => console.error("❌ Error in sendDataToZapier:", error));
});
the export code
import wixData from 'wix-data';
import { fetch } from 'wix-fetch';
export function sendDataToZapier() {
console.log("sendDataToZapier function called");
return Promise.resolve({ success: true, message: "Function executed successfully" });
wixData.query("Events") // Replace with your collection name
.limit(10) // Fetch up to 10 items
.find()
.then((results) => {
console.log("CMS Data Retrieved:", results.items); // Log CMS data
if (results.items.length > 0) {
let dataToSend = results.items.map(item => ({
campaignName: item.title, // Change to your field name
subject: item.subject, // Change to your field name
audienceId: "f6f66dacd5", // Replace with your Mailchimp Audience ID
fromName: "Over Pour Test",
replyTo: "your@email.com",
templateId: "10013094" // Replace with your Mailchimp template ID
}));
console.log("Data to Send:", dataToSend); // Log data before sending
return fetch("https://hooks.zapier.com/hooks/catch/21658839/2acvst3/", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(dataToSend)
});
} else {
console.log("No data found in the CMS collection.");
}
})
.then(response => response.json())
.then(data => console.log("Zapier Response:", data))
.catch(error => console.error("Error:", error));
}