I am trying to create a backend function that will send a triggered email to a specified contact (not a member). The frontend function is fairly straightforward, but I’m having trouble modifying (or even understanding) the more obtuse Wix backend code example.
What I’d like to do is call the backend function with three predefined parameters:
“contactData” is a data array to fill the variables in the triggered email
“contactCode” is the ID of the contact, eg. “a6c1170c-fa3a-41da-923f-7e0eb09d1781”
“emailCode” is the triggered email ID, eg. “U3NJnZb”
Backend call should return a success flag to confirm that email was sent
On the front End: (my code)
import { sendEmailToContact } from 'backend/sendEmailToContact.jsw';
// [...]
sendEmailToContact(**contactCode**, **contactData**, **emailCode**)
.then(success => {
console.log(success);
})
.catch(error => {
console.log(error);
});
On the backend: (Wix sample code, verbatim for now)
import { Permissions, webMethod } from 'wix-web-module';
import { triggeredEmails } from 'wix-crm-backend';
export const myEmailContactFunction = webMethod(Permissions.Anyone, (emailId, contactId, options) => {
return triggeredEmails.emailContact(emailId, contactId, options)
.then(() => {
console.log('Email was sent to contact');
})
.catch((error) => {
console.error(error);
});
});
How to modify the backend code to work with the frontend so that the email is sent according to the three parameters and a success flag is returned?
