Getting the contactId of an user

Hi, I’m coding a page where the user will be able to write their e-mail address and the site will send them an e-mail with a link to a document.

The problem is that I’m using the winCRM.createContact. It works fine if the user doesn’t have a contact yet, but it trows an 403 error when the user already have a contact.

How can I get the contactId from the user that already have a contact? My understanding is that it was supposed to return with the promise of the function, but it’s not working.

Even thou I’m using this, I don’t want users to have a member profile and have to update it.

What you should do is remember the contact Id returned by create Contact for the user unless you make them a site member and have them log in. If you do this then once they are logged in you can use the wix-users.emailUser function.

Otherwise you can remember the contact id-to-email mapping either using wix-storage and essentially writing a cookie to the users browser with the data or you can create a data collection to remember the info. The latter might be better if the user uses multiple devices.

Then, assuming you use a local data collection, when your user gives their email you start by checking the data collection for an email match. If there is one use the stored crm contact id. Otherwise use create contact and save the resulting id and email in the data collection.