Found a problem with this code, which finds a contact’s unique ID based on an email. It works fine until two or more contacts share the same email on file, which I believe is permitted in the case of contacts but not site members.
So I either need to find a way to sort which is the correct user in the case of a duplicate email, or query a different email field altogether. But where is the data for “info.emails.email” stored? CMS/Full Data only shows the login emails of site members; is there a separate CMS collection for contacts?
I also looked in the Contacts section of Dashboard but the two contacts that show up as duplicates in the email query appear there with separate emails. I couldn’t see any hidden email fields or fields for a contact’s alternate/secondary email. In fact, no sign of any duplicate email until I run the code.
const queryResults = await contacts.queryContacts()
.eq('info.emails.email', emailToFind)
.find ({suppressAuth: true});
const contactsWithEmail = queryResults.items;
if (contactsWithEmail.length >= 1) {
contactID = contactsWithEmail[0]._id;
console.log('Found contact info for client: ' + emailToFind + " " + contactID);
} else {
// Handle when no contacts are found
}