How can I GET a contact ID?

created a triggered email template

WHAT I’M DOING:
I have a form and upon submission I am:
storing form data to a collection AND sending an email to myself with the form info

Since I am not sending the email to the VISITOR, nor to a SITE USER… I am doing this on the backend so I can designate the EMAIL TO a hardcoded contact - me.

WHAT I HAVE COMPLETED
created a triggerd email template
I created myself as a CONTACT in my site contact list
and using a call to the backend function: wixCrmBackend.emailContact
I hard coded the email id to the triggered email template
BUT I need the contact ID – and I am not sending the email to the new contact.

NOTE: In the code sample that accompanies the documentation for backed/emailContact —> is comments to user: // Get Contact ID (see attached code scrnshot below)

QUESTION
I can’t find anywhere a function that retrieves / gets a contact or a contact ID.
How can I get the Contact ID for a specific contact?

OR, alternately, is there any way to hardcode the RECIPIENT email address?

Cheers! Cynthia-

The getContactById() function might be what you’re looking for.

Thank you kindly, Yisrrael…

I saw that, but no, I am needing to OBTAIN the contact ID. I don’t have it.

Is there perhaps a GET ALL CONTACTS or something similar, that I can display during execution? I have very few contacts and I only need the ID for this contact once. The contact won’t change going forward.

I suppose I can CREATE a new contact once, using code, and display the ID in the console, that one time. Do you have any other ideas?

I need the contact ID to use in the backend/emailContact function - BUT I have not just previously created a contact. The email is coming to ME.

I need to hardcode the contact ID in the function paramater list, in this line:

wixCrmBackend.emailContact( ’ zzzzz ’ , contactId , { …

I am finding that the ONLY way to obtain a contact ID for use in this way is to have IMMEDIATELY-PREVIOUSLY created the contact, in the lines of code above the call to .emailContact

Again, thank you kindly! : -)

@websvcs OK, so I don’t understand. You state “How can I get the Contact ID for a specific contact?” For what specific contact do you want the ID? How do you identify the contact if you don’t have an ID?

@yisrael-wix Thank you again, Yisrael.

I need to send MYSELF an email with the contents of a form, every time the form is submitted. I am NOT sending the email to the visitor who submitted the form. Only me.

On the backend: It seems there are only 2 recipients to whom one can send an email: to a new contact OR to the site user (member) who is currently logged in.

MISSING: is the ability to use, in the function, a recipient email address for someone who is NOT a contact nor who is a currently-logged in user.

Basically, the need to send a form submission notification email to a 3rd-party email address has been overlooked.

To answer your question…

As a workaround: I added MYSELF to the site contacts, by hand, using the wix site dashboard contacts interface, and I was planning on using MY CONTACT ID as the contact ID in the call: wixCrmBackend.emailContact ('emailid ’ , contactId , { …

It is this contact ID I need - the id associated with my personal entry in the site contact list.

However, I just came up with the idea of a better workaround:
using code, I will CREATE A NEW CONTACT - which will be me - and use the console to display the reply to the log, which will contain the contact ID.

Do you think this will work? Either way, this is all very convoluted…

Do you agree that there is a hole here, and that Corvid needs to allow the sending of an email - via EITHER of the available SendEmail features: backend or frontend - to a 3rd party email address? Or, allow the ability to just hardcode a recipient email address in there.

1 Like

UPDATE: I just discovered that the Fn createContact can be used to UPDATE an existing contact… which ALSO will return the contact ID.

I overlooked this before.

I can just hardcode MY email address in a CreateContact call, pop it in just before the backend emailContact call, and it should work every time.

I’ll let you know what happens.

BUT, my question re: a big hole here still exists. : -) I will submit a FEATURE REQUEST when I am finished here.

OK. My CreateContact is not working. It is such a simple task!!!

Any thoughts? Code is below.

NOTE: I write feedback to the console to follow execution.
It is printing to the screen at every step EXCEPT on the CreateContact step.
It is not creating a contact, and there is no error.
The contact info is hardcoded, and DOES NOT exist in the existing contact list.

Since I am looking to get the ContactID …
I need to successfully display the ContactID after the contact is created.
And I will be adding code to the THEN statement that needs the contactID
THIS is ESSENTIAL

export function myContact() {

    console.log("RECREATE CONTACT");

let firstName = 'myFirstname'
let lastName = 'myLastname'
let email = 'register@pulakico.com'
let phone = ''

let contactInfo = {

 "firstName": firstName,
 "lastName": lastName,
 "emails": email,
 "phones": phone
};

    console.log("tvx NEW CONTACT=");
    console.log(contactInfo);

wixCrm.createContact(contactInfo) 
.then( (contactId) => {

    console.log("tvx contactID=");
    console.log(contactId);

})}

It might be that emails and phones need to be arrays. Also, createContact() requires either a phone or an email so you can probably just leave “phones” out of contactInfo{} .

let email = ['register@pulakico.com'];

Add a .catch() to createContact() to see if and what the error is:

.catch( (err) => {
   console.log('error', err);
});

I’ll give it a shot… thank you!!! I’ll let you know how it goes, one way or the other.

I removed the PH and added a catch as well.

@websvcs Here is a hack …

If you are just sending the triggered email to yourself: go into the editor, go into one of your custom databases (if you dont have one, create one), open the sandbox database and create a new row / record, go to manage fields, turn on owner field > there you will find your ID.

1 Like

@websvcs @yisrael-wix
Did you have any luck?
I also need to GET a contact ID, knowing only their email.

Does anyone know how to do this?

@websvcs just found the answer
https://www.wix.com/corvid/forum/main/comment/5e49c453e6008200176417c5

@wix47224 This is not technically the answer, the one you linked is for site members data not the contacts data.
I am also in need of the ability to just email an email address or get the Contacts ID for the email address entry…

I guess the only fix is to sign up the email as a member account to the site and then hardcode that id in my code;

UPDATE:
For anyone finding this post like i did,
There is a way to use wixcrmbackend to email a contact that is not a member If that contact is not going to change:

import wixCrmBackend from 'wix-crm-backend';

export function myBackendFunction() {
  let contactId = // get contact ID

  wixCrmBackend.emailContact("triggeredEmailID", contactId)
    .then( () => {
      // email has been sent
   } )
    .catch( (err) => {
      // there was an error sending the email
    } );
}

You can hardcode contactId by adding the contact to your contact list under Dashboard > customer management > contact list;
add a name and email address and click save;
Once added click view on the contact in the list and look in the url:

https://manage.wix.com/dashboard/<dashboard-site-id/contacts/view/<CONTACTID>?referralInfo=contacts

Grab the id string from the url between / and ? and put it into the contactId var above.
I’ve tested this and it works - dont forget to add your triggered email ID and its required Variables in string format

2 Likes