# Custom Sign Up form (Velo) using register() api | triggeredemails API Issue

**URL:** <https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654>\
**Category:** Ask the community\
**Tags:** api, question, wix, code\
**Created:** [March 29, 2024, 10:30am UTC](https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654 "2024-03-29T10:30:36Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![FCcoder](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/fccoder/32/33929_2.png) [@FCcoder](https://forum.wixstudio.com/u/FCcoder)\
**Post date:** [March 29, 2024, 10:30am UTC](https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654/1 "2024-03-29T10:30:36Z")

</div>

**Question:**  
I want to set up custom sign up form using code (velo) for my site for which I am using register API to register by approaval token but I am not being able to send verification email at all using triggeredemails (emailcontact()) api to the user. It is getting stuck at - "[“Registration failed:”,"Contact does not have valid email for site “]”. **How do I go past it?**

**Product:**  
WIX Editor - Velo

**What are you trying to achieve:**  
I need to have custom sign up for my website that gets triggered only for users who meet certain criteria.

**What have you already tried:**  
I have also tried ensuring email is in proper format, separately creating a contact for the user, query and send the email for the user.

**Here’s my backend code (register.web.js):**  
import { Permissions, webMethod } from ‘wix-web-module’;  
import { authentication } from ‘wix-members-backend’;  
import { triggeredEmails } from ‘wix-crm-backend’;

export const doRegistration = webMethod(Permissions.Anyone, async (email, password, firstName, lastName) =\> {  
// Convert email to lowercase to ensure case-insensitive handling  
const emailLowercase = email.toLowerCase();

```
const registrationOptions = {
    contactInfo: {
        firstName: firstName,
        lastName: lastName,
        emails: [emailLowercase] // Use the lowercase email
    }
};

try {
    const registration = await authentication.register(emailLowercase, password, registrationOptions);
    console.log('Member registration attempt:', registration);

    if (registration.status.toLowerCase() === "pending" && registration.approvalToken) {
        const emailOptions = {
            variables: {
                name: firstName,
                verifyLink: `https://www.firstcontact.lgbt/post-registration?token=${registration.approvalToken}`
            }
        };

        await triggeredEmails.emailContact('verifyRegistration', registration.member.contactId, emailOptions);
        console.log('Verification email sent using triggeredEmails.');
        return { success: true, message: "Registration successful, confirmation email sent." };
    } else {
        return { success: false, message: "Registration successful but did not enter approval flow." };
    }
} catch (error) {
    console.error('Registration failed:', error);
    return { success: false, message: `Registration failed due to error: ${error.message}` };
}

```

});

export const doApproval = webMethod(Permissions.Anyone, async (token) =\> {  
try {  
const sessionToken = await authentication.approveByToken(token);  
console.log(‘Member approved with session token:’, sessionToken);  
return { approved: true, sessionToken: sessionToken };  
} catch (error) {  
console.error(‘Approval failed:’, error);  
return { approved: false, reason: `Approval failed due to error: ${error.message}` };  
}  
});

---

<div class="post-metadata">

**Author:** ![guy-tadmor](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/guy-tadmor/32/2800_2.png) [@guy-tadmor](https://forum.wixstudio.com/u/guy-tadmor)\
**Post date:** [March 29, 2024, 2:45pm UTC](https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654/2 "2024-03-29T14:45:54Z")

</div>

For which API you get the exception/error for?

---

<div class="post-metadata">

**Author:** ![FCcoder](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/fccoder/32/33929_2.png) [@FCcoder](https://forum.wixstudio.com/u/FCcoder)\
**Post date:** [March 30, 2024, 4:40am UTC](https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654/3 "2024-03-30T04:40:59Z")

</div>

> [@FCcoder](#):
>
> I am not being able to send verification email at all using triggeredemails (emailcontact()) api to the user. It is getting stuck at - "[“Registration failed:”,"Contact does not have valid email for site “]”.

So, I am taking for [emailContact( ) TriggeredEmails](https://www.wix.com/velo/reference/wix-crm-backend/triggeredemails/emailcontact) API. It correctly identifies the contact ID of the user for correct site but says doesn’t have valid email ID for that. I ran the query to find out the details associated with that contact ID in the Wix CRM using getContact () and it gives all the details correctly including the email ID. So, I do not why is it not recognising the email ID.

---

<div class="post-metadata">

**Author:** ![guy-tadmor](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/guy-tadmor/32/2800_2.png) [@guy-tadmor](https://forum.wixstudio.com/u/guy-tadmor)\
**Post date:** [March 30, 2024, 7:34am UTC](https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654/4 "2024-03-30T07:34:03Z")

</div>

This is more or less. the code I use for registration and it works on wix-studio:

import { authentication, authorization } from “wix-members-backend”;  
import { triggeredEmails } from “wix-crm-backend”;

let authResults = await authentication.register(email, password, {  
contactInfo: {  
firstName: firstName,  
lastName: lastName,  
phones: phones,  
emails: [email],  
},  
privacyStatus: “PUBLIC”,  
});

// emailId is the trigger email id  
result = await triggeredEmails.emailMember(emailId, authResults.member.\_id, options);

---

<div class="post-metadata">

**Author:** ![FCcoder](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/fccoder/32/33929_2.png) [@FCcoder](https://forum.wixstudio.com/u/FCcoder)\
**Post date:** [March 31, 2024, 5:29pm UTC](https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654/5 "2024-03-31T17:29:05Z")

</div>

Thank you for sharing this; I keep encountering the same error. Did you separately give any separate permissions for the triggered emails? I have generated the email ID that I use in the following code.

```javascript
import { Permissions, webMethod } from 'wix-web-module';
import { authentication } from 'wix-members-backend';
import { triggeredEmails } from 'wix-crm-backend';

export const doRegistration = webMethod(Permissions.Anyone, async (email, password, firstName, lastName) => {
    // Convert email to lowercase to ensure case-insensitive handling
    const emailLowercase = email.toLowerCase();

   const registrationOptions = {
        contactInfo: {
            firstName: firstName,
            lastName: lastName,
            emails: [emailLowercase] // Use the lowercase email
        },
        privacyStatus: "PUBLIC" // Set privacy status to PUBLIC
    };

    try {
        const registration = await authentication.register(emailLowercase, password, registrationOptions);
        console.log('Member registration attempt:', registration);

        if (registration.status.toLowerCase() === "pending" && registration.approvalToken) {
            const emailOptions = {
                variables: {
                    name: firstName,
                    verifyLink: `https://www.firstcontact.lgbt/post-registration?token=${registration.approvalToken}`
                }
            };

            await triggeredEmails.emailMember('verifyRegistration', registration.member.contactId, emailOptions);
            console.log('Verification email sent using triggeredEmails.');
            return { success: true, message: "Registration successful, confirmation email sent." };
        } else {
            return { success: false, message: "Registration successful but did not enter approval flow." };
        }
    } catch (error) {
        console.error('Registration failed:', error);
        return { success: false, message: `Registration failed due to error: ${error.message}` };
    }
});

export const doApproval = webMethod(Permissions.Anyone, async (token) => {
    try {
        const sessionToken = await authentication.approveByToken(token);
        console.log('Member approved with session token:', sessionToken);
        return { approved: true, sessionToken: sessionToken };
    } catch (error) {
        console.error('Approval failed:', error);
        return { approved: false, reason: `Approval failed due to error: ${error.message}` };
    }
});

```

---

<div class="post-metadata">

**Author:** ![guy-tadmor](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/guy-tadmor/32/2800_2.png) [@guy-tadmor](https://forum.wixstudio.com/u/guy-tadmor)\
**Post date:** [April 3, 2024, 11:25am UTC](https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654/6 "2024-04-03T11:25:33Z")

</div>

> [@FCcoder](#):
>
> `triggeredEmails.emailMember('verifyRegistration'`

The emailId that is the parameter sent to emailMember is generated when you create a template to be used for the registration, you cannot generate it yourself.

In other words, in order to send an email via triggerEmails you need first to defined an email template and use the id of the template when invoking emailMember().

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [April 3, 2024, 11:01pm UTC](https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654/7 "2024-04-03T23:01:31Z")

</div>

[https://russian-dima.wixsite.com/meinewebsite/blank-6](https://russian-dima.wixsite.com/meinewebsite/blank-6)  
Old but gold 😁

---

<div class="post-metadata">

**Author:** ![FCcoder](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/fccoder/32/33929_2.png) [@FCcoder](https://forum.wixstudio.com/u/FCcoder)\
**Post date:** [April 4, 2024, 2:58pm UTC](https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654/8 "2024-04-04T14:58:03Z")

</div>

Yes, ‘verifyRegistration’ is the ID of email template I created. I changed the ID for the eamil template for easier reference. Am I missing out on anything?

---

<div class="post-metadata">

**Author:** ![FCcoder](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/fccoder/32/33929_2.png) [@FCcoder](https://forum.wixstudio.com/u/FCcoder)\
**Post date:** [April 4, 2024, 3:33pm UTC](https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654/9 "2024-04-04T15:33:26Z")

</div>

This is to send email to current member; I need to send it to a contact who is a member we just registered with pending status. So, it will have to be emailContact withing triggeredEmails for me.

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [April 4, 2024, 9:22pm UTC](https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654/10 "2024-04-04T21:22:47Z")

</div>

What you are trying to achieve is a E-Mail-Verification process after a member has signed-up on your site, becomming a member? This is correct?

Your setup-flow should look like…

1. User enters your site.
2. User starts the sign-up-process.
3. User fills in all needed user-data.
4. User clicks the REGISTRATION-BUTTON → registration starts.
5. Before all this happens → you have setted up your triggered-email and got the trigger-ID of that created e-mail in your case → ( **verifyRegistration** ).
6. Inside of your triggered e-mail → you have setted-up the variables including the → **VERIFICATION-TOKEN** \<— you want to send included inside the email, which will be sent to the user’s registered e-mail for → **REGISTRATION-VERIFICATION-PROCESS**.
7. Email goes out to → user entered REGISTRATION-EMAIL.
8. User open the recieved → VERIFICATION-EMAIL.
9. Opening the e-mail → will lead the user to a specific CONFIRMATION-SITE (PAGE), where you have integrated some code for VERIFICATION-PROCESS.
10. As soon the user has been navigated to the CONFIRMATION-PAGE → the CONFIRMATION-PROCESS starts automatically within → **$w.onReady()**
11. Now the included **CONFIRMATION-TOKEN** , which has been \*\*sent via URL-QUERY (by pressing the included BUTTON inside of the CONFIRMATION-EMAIL)\*\*to your CONFIRMATION-PAGE will be used for CONFIRMATION.

**Isn’t this what you are trying to achieve ?**

---

<div class="post-metadata">

**Author:** ![FCcoder](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/fccoder/32/33929_2.png) [@FCcoder](https://forum.wixstudio.com/u/FCcoder)\
**Post date:** [April 5, 2024, 5:02am UTC](https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654/11 "2024-04-05T05:02:43Z")

</div>

Yes! Just one tiny edition (but the main reason why I am going this route) that the registration process gets triggered only for the user who meet certain minimum threshold score calculated based on their responses to custom fields on the front end.

---

<div class="post-metadata">

**Author:** ![FCcoder](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/fccoder/32/33929_2.png) [@FCcoder](https://forum.wixstudio.com/u/FCcoder)\
**Post date:** [April 8, 2024, 7:11am UTC](https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654/12 "2024-04-08T07:11:58Z")

</div>

Yes! Just one tiny edition (but the main reason why I am going this route) that the registration process gets triggered only for the user who meet certain minimum threshold score calculated based on their responses to custom fields on the front end.

---

<div class="post-metadata">

**Author:** ![guy-tadmor](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/guy-tadmor/32/2800_2.png) [@guy-tadmor](https://forum.wixstudio.com/u/guy-tadmor)\
**Post date:** [April 9, 2024, 5:24am UTC](https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654/13 "2024-04-09T05:24:17Z")

</div>

Are you sure that you can change the template id? I didn’t know this is allowed

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [April 9, 2024, 12:55pm UTC](https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654/14 "2024-04-09T12:55:54Z")

</div>

I will reply in few days. —\> not enough free-time at moment sorry.

---

<div class="post-metadata">

**Author:** ![FCcoder](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/fccoder/32/33929_2.png) [@FCcoder](https://forum.wixstudio.com/u/FCcoder)\
**Post date:** [April 10, 2024, 7:23am UTC](https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654/15 "2024-04-10T07:23:36Z")

</div>

Yes, you can!

The problem got resolved for me. The issue was the user was not marked as subscriber, so system was not recognising the email as valid.

---

<div class="post-metadata">

**Author:** ![FCcoder](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/fccoder/32/33929_2.png) [@FCcoder](https://forum.wixstudio.com/u/FCcoder)\
**Post date:** [April 10, 2024, 7:24am UTC](https://forum.wixstudio.com/t/custom-sign-up-form-velo-using-register-api-triggeredemails-api-issue/57654/16 "2024-04-10T07:24:00Z")

</div>

No worries! The problem got resolved for me. The issue was the user was not marked as subscriber, so system was not recognising the email as valid.
