Triggered email template, replace variables in links

Hi Ahabeck -

yes I managed to get it to work but it is not straight forwards as you need to use both the wix-crm and the wix-users apis together in the correct order. The main thing to understand is that the wix-crm emailContact() api can be used on a page visited by an anonymous site user, a Visitor. The wix-users.emailUser() api needs the page user to be logged in so role = Admin or Member.

The other problem I found it that you cannot use the wix-crm record that you get in wix-crm.createContact() with wix-users.register(). The result is that you end up managing two records in the crm each with a different _id. So when sending triggered emails you need to use the correct _id and context. So the flow goes like this:

create contactObject with firstName, lastName, email, …
wix-createContact(contactObject) => contactId [REMEMBER This For your Triggered email}
then
wix-register(email, password) => User record (with a different userId) + ApprovalCode with status Pending
then
wix-crm.emailContact('triggeredEmailName", contactId [from createContact]) with url to verification page containing ApprovalCode
then
user launches the url including the approval code → pass to back end function and call wix-users-backend.approveByToken() => return sessionToken to verification page.

This all seems to work BUT doesn’t actually log the user in with the session token. They still need to login after this sadly.

Hope this helps.