Automate Company Data Enrichment
Overview
This guide will help you enrich your company data directly in Google Sheets using the Lusha Company Enrichment API. You'll be able to send requests to Lusha to retrieve detailed company information, automatically update your sheet, and track which companies have been enriched or failed.
How it Works?
1. Add the Script to Google Sheets
- Open a new Google Sheets
- Go to Extensions > Apps Script
- Delete any existing code and replace it with the following script:
function onOpen() {
const ui = SpreadsheetApp.getUi();
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
ensureHeaders(sheet); // Ensure headers are set
setupStatusField(sheet); // Set up the status field
// Count and display initial statistics
countAndDisplayCurrentStats(sheet);
ui.createMenu('Company Enrichment')
.addItem('Enrich All Companies', 'runEnrichmentAllCompanies')
.addItem('Enrich New/Failed Companies', 'runEnrichmentNewCompanies')
.addItem('Choose Row Range to Enrich', 'chooseRowRangeToEnrich')
.addItem('Set Max Row for All/New Enrichment', 'setMaxRowForEnrichment')
.addToUi();
}
function chooseRowRangeToEnrich() {
const ui = SpreadsheetApp.getUi();
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
// Get the total number of rows with data
const lastRow = sheet.getLastRow();
// Show input dialog for starting row
const startResponse = ui.prompt(
'Choose Row Range - Step 1',
`Enter the STARTING row number (Row 3 to ${lastRow}):\n\nNote: Row 1 contains status info, Row 2 contains headers, so data rows start from Row 3.`,
ui.ButtonSet.OK_CANCEL
);
// Check if user clicked OK and entered a value
if (startResponse.getSelectedButton() !== ui.Button.OK) {
return; // User cancelled
}
const startInputText = startResponse.getResponseText().trim();
const startRowNumber = parseInt(startInputText);
// Validate the start row input
if (isNaN(startRowNumber)) {
ui.alert('Invalid Input', 'Please enter a valid number for the starting row.', ui.ButtonSet.OK);
return;
}
if (startRowNumber < 3) {
ui.alert('Invalid Row', 'Please enter a starting row number 3 or higher (rows 1-2 are reserved for headers).', ui.ButtonSet.OK);
return;
}
if (startRowNumber > lastRow) {
ui.alert('Invalid Row', `Please enter a starting row number between 3 and ${lastRow}.`, ui.ButtonSet.OK);
return;
}
// Show input dialog for ending row
const endResponse = ui.prompt(
'Choose Row Range - Step 2',
`Enter the ENDING row number (${startRowNumber} to ${lastRow}):\n\nStarting row: ${startRowNumber}\nEnter the last row you want to enrich (inclusive).`,
ui.ButtonSet.OK_CANCEL
);
// Check if user clicked OK and entered a value
if (endResponse.getSelectedButton() !== ui.Button.OK) {
return; // User cancelled
}
const endInputText = endResponse.getResponseText().trim();
const endRowNumber = parseInt(endInputText);
// Validate the end row input
if (isNaN(endRowNumber)) {
ui.alert('Invalid Input', 'Please enter a valid number for the ending row.', ui.ButtonSet.OK);
return;
}
if (endRowNumber < startRowNumber) {
ui.alert('Invalid Range', `The ending row (${endRowNumber}) must be greater than or equal to the starting row (${startRowNumber}).`, ui.ButtonSet.OK);
return;
}
if (endRowNumber > lastRow) {
ui.alert('Invalid Row', `Please enter an ending row number between ${startRowNumber} and ${lastRow}.`, ui.ButtonSet.OK);
return;
}
// Confirm the action
const confirmResponse = ui.alert(
'Confirm Range Enrichment',
`This will enrich companies from row ${startRowNumber} to row ${endRowNumber} (${endRowNumber - startRowNumber + 1} rows). Continue?`,
ui.ButtonSet.YES_NO
);
if (confirmResponse === ui.Button.YES) {
updateEnrichmentStatus(sheet, 'In Progress...');
countAndDisplayCurrentStats(sheet);
runEnrichmentFromRowRange(startRowNumber, endRowNumber);
}
}
// [Note: This is a large script - showing key functions for brevity]
// The complete script includes all helper functions for:
// - Setting up headers and status fields
// - Processing companies in batches
// - Handling API responses and errors
// - Updating statistics and status
2. Customize and Run
This script has an action to fetch the API key as a property. In order to add your API key as a property:
- Head to Project Settings
- Under Script Properties, add the property
api_key
- Under the Value, paste your actual API key
Requirements:
- To match a company in Lusha's database using the Company API, you need to populate either the company name (column A) or company domain (column B)
- Run the script by selecting the desired option from the "Company Enrichment" menu in Google Sheets
3. Review and Analyze Results
The script will automatically populate the sheet with enriched company information, such as industry, location, and website details. The "Data Update" column will be updated with the timestamp of the enrichment, and the status will indicate whether the enrichment was successful or failed.
Available Enrichment Options
The Company Enrichment menu provides several options:
- Enrich All Companies: Enriches every row with company data
- Enrich New/Failed Companies: Only processes rows that haven't been successfully enriched
- Choose Row Range to Enrich: Specify exact start and end rows for targeted enrichment
- Set Max Row for All/New Enrichment: Set a limit to cap bulk enrichment operations
Data Fields Returned
The script populates your sheet with comprehensive company information including:
Basic Information:
- Company Name, FQDN, Founded date
- Company Size, Employee count
- Description, Specialties
Industry & Business:
- Main Industry, Sub Industry, Categories
- Technologies, Intent topics
- Revenue Range, Funding information
Location Data:
- Full Location, Address
- Country, City, State, State Code
- Country ISO2 code
Social & Links:
- Company LinkedIn, CrunchBase
- Website and social media links
Status Tracking:
- Enrichment Status, Status Codes
- Error Messages, Timestamps
Troubleshooting
If you encounter any issues:
- Error Messages: Check the "Status Code" and "Message" columns for details on what went wrong during the enrichment process
- Invalid JSON Response: Ensure your API key is correctly entered and that the data formatting in your sheet matches the expected structure
Automating with Triggers (Optional)
To automate the enrichment process, you can set up a time-driven trigger in Google Apps Script to run the script at regular intervals (e.g., daily). This way, your company data will stay up-to-date with minimal manual intervention.
Additional Resources
If you have any questions on the above feel free to reach out the support team:
• Via live chat from the Lusha website
• Your Lusha Dashboard
• Via email: support@lusha.com