Home  >   VTAP Platform   >  Server Jobs Example - Importing Daily Leads from a File

Server Jobs Example - Importing Daily Leads from a File

This article gives you an example of how you can import daily leads from a file using Server Jobs.
A
Abdul Sameer
19 Apr, 2024 - Updated 8 months ago
Table of Contents

Importing Daily Leads from the Website to CRM

Consider CompanyX, which acquires leads from various sources. One of the sources is their website.

On their website, people visit and fill out the form. This data gets stored in a different service. From that service, leads need to be fetched every day and should be created in CRM.

To achieve this, you must create a Server Job to run daily before the work hour starts.

 
async function main() {
    try {
        var response = await vtap.macro.http.get( 'https://www.mywebsite.com/api/leads', {
            headers: {
                Authorization: 'Basic XXXXXXXXXXXX'
            },
            qs: {
                created: '-1 day',
                limit: 100
            }
        });
        if(response && response.status == 200) {
            var data = JSON.parse(response.body);
            for(var index in data) {
                var leadData = data[index];
                await vtap.macro.ws.create('Leads', {
                    firstname: leadData.fname,
                    lastname: leadData.lname,
                    email: leadData.email_work,
                    mobile: leadData.phone_mobile,
                    phone: leadData.phone_office,
                    company: leadData.orgname,
                    designation: leadData.role,
                    leadsource: 'Website',
                    city: leadData.city,
                    state: leadData.state,
                    country: leadData.country,
                    assigned_user_id: '20x3'
                });
            }
        }
    } catch(error) {

    }
}
Was this article helpful?
0  out of  0  found this helpful.
Comments 0
Be the first to comment
© Copyright 2023 Vtiger. All rights reserved.