The following snippet (executed from a lightbox) is intended to send a triggered confirmation email to the logged-in user with regarding a particular action on the site. (This is working.)
// Get current logged in user
let user = wixUsers.currentUser;
userId = user.id;
// Send email confirmation to the logged in user
wixCRM.emailContact("RMabc", userId) //<-THIS WORKS
.then(() => {
//Get list of others from db collection that need a notification email
get_va_list().then((vaList) => {
for (var i = 0, len = vaList.length; i < len; i++) {
console.log("vaList[i].vaContactId = ", vaList[i].vaContactId)
wixCRM.emailContact("RMxyz", vaList[i].vaContactId) //<-THIS DOES NOT WORK
.then(() => {console.log("All Emails sent");})
.catch((err) => {console.log("Email Error = " + err);});
}
wixWindow.lightbox.close("success");
});
})
.catch((err) => {console.log("Email Error = " + err); });
I then also want to send another triggered email to a small list of three other site members that the action took place. (Shown above in the second wixCRM.emailContact call.) This is not working.
I have gathered a list of the three contact_id's when they were created and stored them in a collection for retrieval here. (They appear to be retrieving correctly and are correctly stored in the vaList[i].vaContactId variable as proven by the console.log output. I have compared each with the userId obtained upon registration (not the collection ID when stored in the db) when they were created elsewhere in my code and they appear to be stored/retrieved correctly.)
When the code tries to send this second set of emails, I get the following error. There are three emails in my list.
(3)POST https://www.mywebsite.com/_api/shoutout/v1/emailContact 401 (Unauthorized)
Uncaught (in promise) Failed to execute 'postMessage' on 'Worker': function Sb(){return!1} could not be cloned.
I need this second set of emails to be sent whenever any site member performs this action (regardless of the permissions of the logged in user.)
I also tested the code, "RMxyz" with the logged in user just to ensure the triggered email was properly configured and it sent properly.
Any thoughts on what I could be doing wrong? I would be most appreciative of any advice!