"Failed to fetch" when sending triggered email

I’m having the same problem. I tried using “onAfterSave” and it did not help. I am receiving an “TypeError: failed to fetch” after running the following code:

let firstName = $w('#firstName').value;
let email = $w("#email").value;
wixCRM.createContact({
  "firstName": firstName,
  "emails": [email]
})
.then((contactId) => {
  wixCRM.emailContact(triggerEmailID, contactId, {
    "variables": {
      "firstName": "eric"
    }
  })
  .then( () => {
    console.log("success");
    wixLocation.to(linkPage);
  })
  .catch((err) => {
    console.log("reached3");
    console.log(email);
    console.log(triggerEmailID);
    console.log(contactId);
    console.log(err);
  });
});