Home  >   FAQs   >  How to write a script for a server job for importing daily leads from a file?
FAQs in this section

How to write a script for a server job for importing daily leads from a file?

Table of Contents
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.

For that, 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 FAQ helpful?
0  out of  0  found this helpful.
Comments 0
Be the first to comment
© Copyright 2023 Vtiger. All rights reserved.