Send Triggered Email to a user not logged in

According to the API reference for emailContact I cannot find anywhere that it says that it is only currently logged in user. In the wixUsers emailContact it says that the user logged in will get the email. But in the emailContact it just says that you need to provide the function with a valid userid.

API Reference:

Error message:

contactId does not match current session contact (401)

So how can we send emails using triggered email to a list of users in the Wix CRM module. I have a client where this is a requirement and I thought according to the emailContact that this was doable.

So the only way that i’ve been able to accomplish this is by ‘creating’ a new member (again) and then sending email. It hasn’t worked any other way for me (for the same reason > the id).

This article specifies this method: Velo Tutorial: Sending a Triggered Email to Contacts | Help Center | Wix.com

(couldn’t copy code in code block because it added it ‘funny’) Here is snapshot:

Hello, Earlier, I designed triggered emails user code to send our emails to new contacts. This is done after user filled in a form. It was working fine. Now all of a sudden, I see the feature doesn’t work. In chrome console logs, I see the following error message. “Contactid doesn’t match the current session contact (401)”.
I understand there is a third party tool that I can use. But I would like go know what could be the possible reasons for it to stop working. Please help me resolve this. Any help is truly appreciated. Here is the form I was talking about. Please answer the questionnaire slideshow and you are supposed to receive email.

https://desouzadavid.wixsite.com/mysite-3/home

Thanks a lot for the support.

I am having exactly the same problem… no code is doing the trick for me. I always get the rejection:
Uncaught (in promise) contactId does not match current session contact (401)

any ideas?

Hi there!!! thank you for the amazing work! I have been learning from you for a time now! Do you know if this is working? I can’t get it to work no matter what I do I always get the rejection:

Uncaught (in promise) contactId does not match current session contact (401)

perhaps do you have an idea why this could be?

Cheers and thank youuu!

Same here! Wix Developer: Are there any plans to fix this limitation. I would like to be able to send to Any Site Member. For example, when a new member joins I need to send notifications to: club president, membership director, sales manager, etc. I already have a triggered email set up but it only goes to the logged in member.

That was sorted out many months ago, just use Wix CRM Backend and the emailContact function.
https://www.wix.com/corvid/reference/wix-crm-backend.html#emailContact
Wix CRM Email Contact - Sends email to contact.
Wix CRM Backend Email Contact - Sends email to contact that you have specified.

Same with Site Members when using Wix Users.
https://www.wix.com/corvid/reference/wix-users-backend.html#emailUser
Wix Users Email Contact - Sends email to the logged in user
wIX Users Backend Email Contact - Sends email to the site member that you have specified.

Or, if it just a simple notification, then you could have set up a simple Wix Automation months ago too.
https://support.wix.com/en/ascend-by-wix/wix-automations

1 Like

Thanks. I will check out backend api. Already have wix automations set up but doesnt work unless a Submit button stores the database record. In my case, I store the fields for the database entry in an array Then call wixPay. If payment is successful then Insert the database record. Insert will Not trigger an automation???

When that didnt work I just gave up… more important things to fix. I have just been forwarding the notification that I receive from wix pay. “Notice, You Have A Payment”

Have NOT yet figured out how to get this to work. For the life of me I do not understand why they made this so convoluded! Why not just use the users frigging email address?

From the Code in the API Reference:

import wixUsers from ‘wix-users-backend’;
export function myBackendFunction() {
let userId = // get user ID <<<<<<<<<<<<< HOW THE FXXK DO YOU GET THE USER ID !!! SEE MY
TEST BELOW WHERE I ATTEMPTED TO RETRIEVE IT…

wixUsers.emailUser(“emailID”, userId)
.then( () => {
// email has been sent
} )
.catch( (err) => {
// there was an error sending the email
} );
}

I put together a simple piece of code to TRY AND GET THE USER ID as follows and Even that does not work!

My Wix code:

import wixData from ‘wix-data’;
import wixUsers from ‘wix-users-backend’;

let options = {
‘suppressAuth’: true
}

$w.onReady( function () {

})

export function messageSendButton_click(event) {
let AdminEmail = $w(“#input1”).value;
console.log("Retrieving ID for: ", AdminEmail)

    wixData.query("Members/PrivateMembersData") 
     .contains("loginEmail", AdminEmail) 
     .find(options) 
    .then(res => {  

let wixLogin = res.email;
let wixID = res._id;
console.log("Login Email and ID: " ,wixLogin, “-”, wixID)
}
)
}

Running this gives errors on JDeveloper console as follows:

Loading the code for the site. To debug this code, open masterPage.js in Developer Tools.
console.js:35 Loading the code for the Test Triggered Email page. To debug this code, open wgg1l.js in Developer Tools.
console.js:35 [datasetReady event] triggered on wix-dataset
console.js:35 Retrieving ID for: cvoapresident@hotmail.com
console.js:35 Login Email and ID: undefined - undefined

========================
I also created an email Backend and coded it there, but as Site Monitoring is not yet released I cannot tell WTF it is doing there.

This is so… frustrating!!! Please don’t point me to all the examples and docs! Been There Done That! Please take a look at the code and tell me what I am doing wrong!

Thanks
JD

The userID for the specific site member you can find in your dataset under the ID field, exactly the same as Wix Users does for the logged in user id.

let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"

You just have to manually add the userid of the specific member that you want the email to be sent too if it is going to be the same user all the time.

Otherwise you can search a created dataset for the ID (_id) system field.
CMS (Formerly Content Manager): About Your Collection Fields | Help Center | Wix.com

Or in your case, search the Wix Members app own automatically added Members/PrivateMembersData Collection and search through the ID (_id) field of that instead.
Velo: Wix Members "PrivateMembersData" Collection Fields | Help Center | Wix.com

Also, you are much better off using the eq. function and not contains.
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#eq

.then( (email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query("Members/PrivateMembersData")
.eq("_id", userId)
.find(); 

Site Monitoring is up and running too.
https://support.wix.com/en/article/corvid-about-site-monitoring
https://support.wix.com/en/article/corvid-connecting-site-events-to-a-monitoring-tool-advanced
https://www.wix.com/corvid/reference/site-monitoring.html

Thanks. I originally tried using the ID fields of my custom members database and retrieved that just by looking at the database manager. I then created CVOA-Officers database that contained the email address and that “_id” for each of the site Admins that I wanted to email to. DID NOT WORK. Got message that could only sent to currently logged in user…

As for your code snippet referenced in: https://support.wix.com/en/article/corvid-wix-members-privatemembersdata-collection-fields#id-_id

wixData.query("Members/PrivateMembersData")
  .find()
  .then( (results) => {
    // handle the results  See my code below:  looks the same to me?
  } );

Here is my code from above:
wixData.query(“Members/PrivateMembersData”)
.contains(“loginEmail”, AdminEmail
) .find(options)
.then(res => {
let wixLogin = res.email;
let wixID = res._id;
console.log("Login Email and ID: " ,wixLogin, “-”, wixID)
}
BUT I GET the console.log message:
console.js:35 Login Email and ID: undefined - undefined


Agreed, I DID try to use .eq but when it did not match I changed to .contains on a whim… I have turned this thing more ways than a monkey can turn a peanut…


Thanks For Site Monitoring tip, I will check it out…

I added some code to check for FOUND count. Looks like it IS finding the member but cannot display the values. Is it because the _id is a UID rather than a string?

wixData.query(“Members/PrivateMembersData”)
.eq(“loginEmail”, AdminEmail)
.find(options)
.then(res => {
let resultCount = res.totalCount;
let firstItem = res.items[0]; //see item below
let wixLogin = res.email;
let wixID = res._id;
console.log(“Login Email and ID: " ,wixLogin, “-”, wixID)
let found = resultCount;
if (found === 0) {
console.log(“NO Match On Email “)
$w(”#text238”).text = “email NOT Found”;
$w(”#text239").text = “none”;
} else
{
console.log(“Found “, found ,“Match”)
$w(”#text238”).text = wixLogin;
$w(“#text239”).text = wixID;
}
}
)

I GET the email NOT found and none if I enter a bogus email address. If I enter a known email address I get Found 1 Match…

Thanks
JD

I went into the Dashboard/Site Members: Located a member and added a custom value for “_id”. My search code DOES say a match was found… but it will not display.

Have you already got a ID for that user as once defined you can’t change it.
https://support.wix.com/en/article/about-your-database-collection-fields#system-fields

A unique identifier for the item. You can assign the ID a value when you import new data from a CSV file. Otherwise the ID is a random UUID.
Using Corvid by Wix you can also assign the ID a value when adding items with the Data API.
Once defined the ID cannot be edited.

Also, note that the Wix Members app collection that you are using is read only, so it will already have an ID that you can’t change yourself.

https://support.wix.com/en/article/corvid-wix-members-privatemembersdata-collection-fields#id-_id

ID (_id)

Description : The member ID that was created by the server. This is a system field and is hidden by default.
Type : Text
Can connect to data : Yes
Can use in dynamic page URL : Yes
Read-only : Yes

If the Wix Members accessible from my site Dashboard/Customer Management/Site Members is READ ONLY the WHY is there an INPUT field where you can set or change a value?

DAMMIT. I guess I will spend some more consulting dollars! This is all so Fscked up!

I am retired Oracle database engineer. Actually developed Oracle applications using Java. Wrote C-language code for 20 years, been coding this Wix site for two years. Just when I think I know what I am doing I hit a wall with dumb convoluted shit like this!

I WISH I HAD NEVER IMPLEMENTED ON WIX!

1 Like

That is because your Wix Members app puts the Members/PrivateMembersData collection along with your other datasets in your Site Structure. However, as it is a Wix app collection it is not shown in your dataset list through your Wix Dashboard, that will only show the datasets that you yourself have created.

You can’t change anything in this dataset itself and the permissions are set as Site Member Author only.

The Site Members on the Wix Dashboard is through Wix Users as it is for Site Members.

What’s the difference between wix-crm and wix-users?
The CRM API contains functionality for working with your site’s contacts.
The Users API contains functionality for working with users who are logged-in members.
Note that all members are also contacts, but contacts are not necessarily members.

Thanks. I understand the differences between CRM and USERS… I just cannot figure out HOW TO GE THE FREAKING ID FROM ANYONE EXCEPT CURRENT LOGGED IN USER!

GIVE ME A BEER! I’M DONE!

No matter what I did, I couldn’t make it work with the contacts. I found a solution using sendgrid api. You have 100 mails a day which is enough for my needs. Maybe you can try it this way

I implemented sendgrid a year ago. It is not reliable. Sometimes you would get the emails, sometimes you would not. Reason: With the free plan you dont get a dedicated IP address for email server… they use public servers… occasionally it chooses one that may have the domain of the email you are sending to blocked.