Getting a webhook response

Hi helpful people

I am currently using a webhook to trigger a flow when a button is clicked. But the code to handle the repsonse is not working. I believe it is because the webhook is a webhook, and the 200 response is sent to and not webflow, but i am not sure, not that great in webhooks. Here is the code, any help would be appreciated.

document.addEventListener(‘DOMContentLoaded’, function() {
const form = document.getElementById(‘wf-form-onboarding’);
const submitButton = document.getElementById(‘webhook-button-trigger’);
const loadingAnimation = document.getElementById(‘loading-shimmer’);
const aiOutput = document.getElementById(‘ai-output’);

form.addEventListener('change', updateTotalCredits);

function updateTotalCredits() {
// Get all checkboxes with a specific class, adjust as needed
const checkboxes = document.querySelectorAll(‘.ms-checkbox-copytype’);

// Calculate total credits based on selected checkboxes
let totalCredits = 0;
checkboxes.forEach(checkbox => {
    if (checkbox.checked) {
        totalCredits += parseInt(checkbox.value, 10);

// Update the value of the hidden input
document.getElementById('total-credits').value = totalCredits;


submitButton.addEventListener('click', function(event) {
  event.preventDefault(); = 'block'; = 'none';

  const formData = new FormData(form);

  fetch('', {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    body: JSON.stringify({ data: Object.fromEntries(formData) }),
  .then(response => response.json())
  .then(data => {
   if (response.status === 201) {
        = 'block'; = 'hide';
    } else {
        = 'hide'; = 'hide'; 
  .catch(error => {
    // Handle errors


In Make’s webhooks, you have the option to immediately return a code, or to defer that to a separate response webhook.

When I need to return data, I usually have a router/switch to determine success and error states, and then return the correct response code, messaging and data in the response webhooks.