Home  >   FAQs   >  How to write a server script for contact email validation and data enrichment?
FAQs in this section

How to write a server script for contact email validation and data enrichment?

Table of Contents
Consider a marketing firm CompanyX who acquire leads from various sources. They get only the names and email addresses of leads. They want to enrich lead information whenever they are created. This will help them prepare a marketing strategy for targeted marketing.
To do this, first you must create a custom checkbox field to know if the email address is verified. And create a workflow or process to enrich lead information.
 
async function main(record, user) {
    //Get lead's email address
var email = record.email;
if(email) {
    try {
             //Send request to enrich service to get data by email address
             var response = await vtap.macro.http.get(
                 'https://www.enrichservice.com/api/query', {
                     headers: {
                         Accesstoken: 'XXXXXXXXXXXXXXXXXX'
                     },
                     qs: {
                         email: email
                     }
                 }
             );
         
             if(response && response.status == 200 && response.body) {
                 var data = JSON.parse(response.body);
                 record.firstname = data.fname;
                 record.lastname = data.lname;
                 record.mobile = data.phone_mobile;
                 record.company = data.orgname;
                 record.designation = data.role;
                 record.industry = data.industry;
                 record.website = data.website;
                 record.twitter_username = data.twitter;
                 record.country = data.address.country;
                 record.state = data.address.state;
                 record.city = data.address.city;
                 record.code = data.address.zip;
                 record.cf_email_verified = 1;
             } else {
                 record.cf_email_verified = 0;
             }
    } catch(error) {
        //Uncheck email verified checkbox
        record.cf_email_verified = 0;
    }
}


//Return record data with updated value as process will update values in CRM
return record;
}

Explanation
  • In workflow or process, will add conditions to trigger this script for leads when an email is changed and the email verified checkbox is disabled.
  • If the email value is there, send http get request to enrich the service by setting the required access token and email value in the query string.
  • If the request is successful, set lead field values based on data received from the enrich service. Also, set the email verified checkbox to 1 to know that the email is verified.
  • If the request fails or no data is received from the request, set the email verified checkbox to 0.
  • Return the updated data. Workflow or process will update changed data in the CRM lead record.
Was this FAQ helpful?
0  out of  0  found this helpful.
Comments 0
Be the first to comment
© Copyright 2023 Vtiger. All rights reserved.