Hello, I am trying to make a script to create a contact, then send a triggered email to that contact. Whatever I do, I always get " Wix code SDK error: variable “contactTo” value must be uuid. For more information visit https://www.wix.com/velo/reference/wix-crm/triggeredemails-obj/emailcontact" or “error” or " Bad Request: please check the user inputs."
I have tried:
wixCrm.createContact( {
6 "firstName": $w("#firstName").value,
7 "lastName": $w("#lastName").value,
8 "emails": [$w("#email").value],
9 "phones": [$w("#phone").value]
10 } )
11 .then( (contactId) => {
12 wixCrm.emailContact("thankyou", contactId, {
13 "variables": {
14 "firstName": $w("#firstName").value,
15 "lastName": $w("#lastName").value
16 }
17 } );
and:
import { contacts, triggeredEmails } from 'wix-crm';
2
3$w.onReady(function () {
4 $w('#createContact').onClick(async () => {
5 const firstName = $w('#firstName').value;
6 const lastName = $w('#lastName').value;
7 const email = $w('#email').value;
8 const phone = $w('#phone').value;
9
10 const contactInfo = {
11 name: { first: firstName, last: lastName },
12 emails: [{ email: email }],
13 phones: [{ phone: phone }],
14 };
15
16 let resolvedContact;
17
18 try {
19 resolvedContact = await contacts.appendOrCreateContact(contactInfo);
20 console.log('Resolved to contact', resolvedContact);
21
22 if (resolvedContact.identityType !== 'CONTACT') {
23 console.log('Current contact is already a site member. Not sending a welcome email.');
24
25 // emailContact() cannot be used to email site members.
26 // If you want to email a member, use triggeredEmails.emailMember()
27
28 return;
29 } else {
30
31 const emailId = 'Spp8KfP';
32 const contactId = resolvedContact.contactId;
33 const options = {
34 variables: { firstName: firstName, lastName: lastName },
35 };
36
37 await triggeredEmails.emailContact(emailId, contactId, options);
38 console.log('Emailed contact');
39 }
40 } catch (error) {
41 console.error(error);
42 }
43 });
44});
I have played around with the code so much and still can’t get any solution.
Can I have some help with this?