Hi Ross,
I noticed a couple of issues with your example:
-
The argument of wixCRM.createContact has a predefined set of fields it recognizes. In your case, First Name , Last Name , Email should be firstName , lastName , emails (note, emails is an array).
-
Is Verify a valid triggered email ID? I created a triggered email and my autogenerated ID was R5bgzfr .
I used your code to recreate the example and it worked for me (replace R5bgzfr with your ID):
import wixCRM from "wix-crm";
$w.onReady(() => {});
export function button1_click(event, $w) {
const contactInfo = {
// https://www.wix.com/code/reference/wix-crm.html#ContactInfo
firstName: $w("#input1").value,
lastName: $w("#input2").value,
emails: [$w("#input14").value]
};
const contactId = wixCRM.createContact(contactInfo).then(
contactId => {
console.log(`Contact ${contactId} has been created.`);
const triggeredEmailId = "R5bgzfr"; // https://support.wix.com/en/article/creating-a-triggered-email
const triggeredEmailOptions = {
variables: {
subscribername: $w("#input1").value
}
};
return wixCRM
.emailContact(triggeredEmailId, contactId, triggeredEmailOptions)
.then(
() => {
console.log(`Triggered email ${triggeredEmailId} has been sent.`);
},
error => {
console.error("An error occured while emailing the contact.", error);
}
);
},
error => {
console.error("An error occured while creating a contact.", error);
}
);
}
I added logging. Open Developer Console in preview (or the console of your browser developer tools) to see them.
Also note that sending an email doesn’t work in Editor’s preview - it only works on a published website. While creating a contact does work in the preview.