Hello Yisrael,
I got the createContact() working. My code is inside onReady. I save the data using
$w('#dataset1').setFieldValues( {
"title": TeamName,
"firstname": $w("#input2").value,
"lastname": $w("#input3").value,
"email": $w("#input4").value,
"cell": $w("#input5").value
});
$w('#dataset1').save();
then the onAfterSave event, I got working, to create a contact then I try to use the _id to send a Triggered Email. This fails with FAILED TO FETCH. Did I loose my Triggered Email access somehow? I bought more emails so I have 7, but it’s not working. Here’s my code. which seems to go all the way to
wixCRM.emailContact(‘Sosgvzd’, contactId, { //SrhtD9P // Sosgvzd
or
triggeredEmails.emailContact(‘Sosgvzd’, contactId, { //SrhtD9P // Sosgvzd
aren’t both the same?
Here’s my code:
//import wixData from 'wix-data'; // don't use this, no onAfterSave callback
import wixLocation from 'wix-location';
import wixCRM from 'wix-crm'; // using this now for triggered email
import { triggeredEmails } from 'wix-crm'; // tried this not different
import {memory} from 'wix-storage';
import {fetch} from 'wix-fetch'
//import {sendEmail, sendEmailWithRecipient} from 'backend/email';
$w.onReady(function () {
let TeamId = memory.getItem("TeamId");
let TeamName = memory.getItem("TeamName");
$w("#text63").text = TeamName;
$w('#dataset1').onAfterSave( () => {
console.log("onReady dataset1.onAfterSave()");
let TeamName = memory.getItem("TeamName");
let InviteeName = $w("#input2").value + " " + $w("#input3").value;;
let firstName = $w('#input2').value;
let lastName = $w('#input3').value;
let email = $w('#input4').value;
let phone = $w('#input5').value;
console.log("SENDING EMAIL"+" mailto:"+email+" TeamName-"+TeamName+" phone="+phone+" InviteeName="+InviteeName);
let contactInfo = {
"firstName": firstName,
"lastName": lastName,
"emails": [email],
"phones": [phone],
};
console.log("contactInfo set "+contactInfo)
wixCRM.createContact(contactInfo)
.then( (contactId) => {
console.log("Contact Created contactId="+contactId); // THIS MESSAGE SHOWS CORRECTLY
//triggeredEmails.emailContact('Sosgvzd', contactId, { //SrhtD9P // Sosgvzd
wixCRM.emailContact('Sosgvzd', contactId, { //SrhtD9P // Sosgvzd
"variables": {
"InviteesName": InviteeName, // these 2 variables are in the triggered email
"TeamName": TeamName
}
})
.then( () => {
console.log("Triggered Email SENT"); // THIS MESSAGE NEVER SHOWS, I GET ERROR "FAILED TO FETCH"
// FOLLOWING CODE IS EXECUTED ON SUCCESS OF EMAIL SEND, I CALL THIS PAGE FROM 2 PLACES, AND IT MUST RETURN ONE OF 2 PLACES BASED ON "from" in memory
/* if(memory.getItem("from") == "Create-Team"){
wixLocation.to("/account/Create-a-Team-3");
}else{
wixLocation.to("/account/Edit-Team");
} */
})
} )
.catch( (err) =>{
let errorMsg = err;
console.log("TRIGGERED EMAIL ERROR-->",errorMsg);
});
}); // onAfterSave
// button2 is the save and invite button
$w("#button2").onClick( (event) => {
$w('#dataset1').setFieldValues( {
"title": TeamName,
"firstname": $w("#input2").value,
"lastname": $w("#input3").value,
"email": $w("#input4").value,
"cell": $w("#input5").value
});
$w('#dataset1').save();
}); // BUTTON2 CLICK END
}); // ONREADY END
/*triggeredEmails.emailContact('Sosgvzd', emailadd, {
variables: {
TeamName: TeamName,
//ProjectName: <enter-value-here>,
InviteesName: InviteeName,
// name: <enter-value-here>
}
});*/
Yisrael, do I have a back end problem? I’m using wixCRM.emailContact or TriggeredEmails.emailContact
Why FAILED TO FETCH? Is it in the email definition somehow?