triggeredEmail issues

I do not seen to be able to get the triggeredEmail code to work, Here is what I have for a page I am workng on. If anyone can see any obvious errors I would appreciate your feedback.

import wixData from 'wix-data';
import wixLocation from 'wix-location';
import { fetch } from 'wix-fetch';

$w.onReady(function () {
  loadLastFourEnteredRecords();
});

function loadLastFourEnteredRecords() {
  wixData.query('dataset-name-here')
    .limit(8)
    .descending('_updatedDate') // Sort in ascending order by _updatedDate
    .find()
    .then((results) => {
      const items = results.items;
      $w('#repeater1').data = items;
    })
    .catch((error) => {
      console.error(error);
    });
}

$w('#button2').onClick(refreshAndLoadRecords);

function refreshAndLoadRecords() {
  loadLastFourEnteredRecords();
  setTimeout(() => {
    wixLocation.to(wixLocation.url);
    sendTriggeredEmail(); // Move this line here
  }, 100); // Adjust the delay duration as needed
}

function sendTriggeredEmail() {
  const memberId = 'member-id-here'; // Replace with the actual member ID

//TRIGGEREDEMAIL CODE STARTS HERE

  const url = '/_functions/sendTriggeredEmail'; // Replace with the actual backend function URL

  fetch(url, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ memberId })
  })
    .then((response) => {
      if (response.ok) {
        console.log('Triggered email sent successfully');
      } else {
        console.error('Error sending triggered email:', response.status);
      }
    })
    .catch((error) => {
      console.error('Error sending triggered email:', error);
    });
}

Based on the code you provided, the logic for sending the email is inside of your HTTP Functions (http-functions.js) within the post_sendTriggeredEmail() method.

I would check the logic inside of that method to understand what is going wrong.

Unless you expect other external services to call this function as a API, you should instead send the triggered email via a backend .jsw file.

Check out the following Velo Example to see how this can be accomplished.