Hi!
I am trying to execute the TriggeredEmails on the backend.
The process here is to email a Contact everytime they submitted a form.
Below are my codes:
import { contacts, triggeredEmails } from 'wix-crm-backend';
export async function sendEmailToContact(emailToFind,fName,emailID) {
let contactId;
let options = {
variables: {
"firstName": fName
}
};
const queryResults = await contacts.queryContacts()
.eq('info.emails.email', emailToFind)
.find();
const contactsWithEmail = queryResults.items;
if (contactsWithEmail.length >= 1) {
console.log('Found contact');
contactId = contactsWithEmail[0]._id;
} else {
console.log('No contacts found');
// Handle when no contacts are found
}
try {
await triggeredEmails.emailContact(emailID, contactId, options);
console.log('Email sent to contact');
} catch (error) {
console.error(error);
// Handle the error
}
}
It is producing an error on the “const queryResults = await contacts.queryContacts()” part and I do not know why.
I just copied it from this link. and added an email_ID and options in its parameters.