Articles in this section
Server Scripts & Jobs Overview Using Custom Server Scripts in Processes, Workflows, and Approvals Running Custom Background Tasks with Vtiger Server Jobs Writing Code for Server Scripts and Jobs Helper Method for Server Scripts and Jobs - Debugging Helper Method for Server Scripts and Jobs - HTTP Request Helper Methods for Server Scripts and Jobs - Vtiger REST API Server Scripts Example - Contact Email Validation and Data Enrichment Server Scripts Example - Update Credit Score of a Contact Server Scripts Example - Calculate Organization Outstanding Invoice Amount Server Scripts Example - Set Case SLA by Created Day Server Jobs Example - Update Stocks Weekly in Warehouse System Server Side Scripts & Jobs User Guide

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  1 year ago

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) {

    }
}
Related articles
Server Scripts & Jobs Overview Using Custom Server Scripts in Processes, Workflows, and Approvals Running Custom Background Tasks with Vtiger Server Jobs Writing Code for Server Scripts and Jobs Server Scripts Example - Update Credit Score of a Contact
Home Privacy Policy Terms of Service Security Center Policy & Legal Center Contact Us
© Copyright 2025 Vtiger. All rights reserved.
Powered by Vtiger
Facebook Twitter Linkedin Youtube