Home  >   VTAP Platform   >  Server Scripts Example - Contact Email Validation and Data Enrichment

Server Scripts Example - Contact Email Validation and Data Enrichment

This article gives you an example of how you can do Contact email validation and data enrichment using Server Scripts.
A
Abdul Sameer
19 Apr, 2024 - Updated 8 months ago
Table of Contents

Contact Email Validation and Data Enrichmen

Consider a marketing firm CompanyX 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 achieve this, 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 article helpful?
0  out of  0  found this helpful.
Comments 0
Be the first to comment
© Copyright 2023 Vtiger. All rights reserved.