Need to get a ContactID from the contacts email address

Hello,

I’m trying to create an http-function to send a triggered email to a customer contact, not a member. The input I have is the contacts email address. Can someone please point me in the direction of the correct API to use to do this?

I have the code to send the triggered email, the only thing I’m missing is how to get the Id of the contact to send it to.

let ContactID = ??? HOW DO I GET THIS?

wixCrmBackend.emailContact(form, contactID)
                .then ( () => {
                    console.log("Triggered email sent");
                })
                .catch( (err) => {
                    console.log(err);
                });

Hello friend.

You need to create a function to find the contact for you, either with name or email as a search parameter, for example:

import { contacts } from 'wix-crm-backend'

async function findContactIdByEmail(email) {
 const queryResults = await contacts.queryContacts()
        .eq("info.emails.email", email)
        .find()
 const contactsFound = queryResults.items
 return contactsFound[0]._id // This will return the first ContactID found with the email providaded
}

This function will provide the first ContactID found with the email provided.

To use this function, you just need to do something like this:

let contactId = findContactIdByEmail(“sheldonlee@wix.com”)

Thanks!