contactId

I need to send an email to a specific contact Id from the code.
How can I know what is the contactId of a specific user?

or in other words - is the contact id the same as the user id? if so i know the userId but wix doesn’t let me send this user an email. What can i do?

Cannot be done with Wix Triggered Emails. Must be done with email service integrations

Hi,
Please share your code so we can assist you, if you need guidelines check out this article about sending email via code.

It’s o.k. I’ve used an email service to do it

For anyone looking to do this, it is possible to look up the contact Id (or any other contact information) for users who are registered as site members.

Create a backend file members.jws and put this code in it. Then call it to find any member by email address. The function findMember returns an id if found, or otherwise it returns 0.

import wixData from 'wix-data';
let options = {
"suppressAuth": true,
"suppressHooks": false
};

export function findMember(email){
var Id
return wixData.query("Members/PrivateMembersData").eq("loginEmail", email).descending("lastLogin").find(options)
.then((filteredmembers)=>{
    if (filteredmembers.items.length > 0){
        Id = filteredmembers.items[0].contactId
        let foundemail = filteredmembers.items[0].loginEmail
        let message = "Member found " + foundemail + " " + Id
        console.log(message)
        }
    else {Id = 0}
return Id
})
.catch((err)=>{
let em = "could not search members database" +err
console.log(em)
})
}

Then call this function findMember from another module. In the example below we return an ID if one exists in the member Database for the give email, if not, an ID is created with wixCrm and returned.

import {findMember} from 'backend/members'

function getID(eMail, firstName, lastName){

return findMember(eMail).then((Id)=>{
if (Id !== 0){
    console.log("existing member.");
    return Id
    }
else {
    console.log("create new contact");
    return wixCrm.createContact( {"firstName": firstName, "lastName": lastName, "emails": [eMail]} )
    }

})

}

Thanks for adding the code example, although please add it as a new post rather than jumping onto the end of a post from 2018.

Plus, should eMail not be email?