Sending triggered email has mind of its own

Hi been trying to send a triggered email with code to a new contact. But sometimes it sends, sometimes it doesn’t.

The contact keeps getting created. So that step is working. But the error in the preview is shown for sending the email. Sometimes it goes through without error but the email is not sent.

Really frustrating. And not sure what I am doing wrong/right? Code is below.

Any suggestions?

import wixCrm from 'wix-crm';

$w.onReady(function () {
});
export function button1_click(event) {
wixCrm.createContact({
"firstName": $w('#input1').value,
"emails": [$w("#input3").value],
"number": $w("#input2").value
})
.then((contactId) => {
wixCrm.emailContact("Rqx3cXf", contactId, {
"variables": {
"name": $w("#input1").value,
"number": $w("#input2").value
}
})
.then(() => {
console.log("success");// do something after the email was sent
})
.catch((err) => {
console.log("error");// handle the error if the email wasn't sent
});
});
}

Your code looks OK upon inspection. A couple things you can do to try to narrow down what’s wrong…

Your current code has a .catch() for emailContact() . You should display the error that you are getting, like this:

console.log("error", err);

Add another .catch() to the createContact() call, again displaying the error.

Hopefully this will shed some light on what’s going on.