How to Automatically Send Leads from Google Sheets to Grinfi
This guide will help you set up a basic integration between Google Sheets and Grinfi using Google Apps Script. Once
configured, data for new contacts will be automatically transferred to your chosen Grinfi list immediately after a new
row is added to the spreadsheet.
Prerequisites
To complete the setup, you will need:
- Grinfi API Key.
- List UUID: A unique identifier for the list in the system where new contacts will be stored.
- Prepared Google Sheet: A document created with relevant columns for data entry: First Name, Last Name, LinkedIn ID
(or URL), Email, etc.
Additionally: review the full Grinfi API documentation.
π‘ Note: Google Apps Script has execution limits: up to 90 minutes of execution time per day (for free accounts) or 6
hours (for Workspace). For bulk imports (>100 leads at a time), it is better to use the CSV import feature directly in
Grinfi.
Step 1. Preparing the Spreadsheet Structure
For the script to work correctly:
- Create column names only in the first row of the sheet
- Name the columns exactly as shown in the list below (in English, respecting spaces and capital letters)
- "LinkedIn ID" column is mandatory: add the contact's LinkedIn profile link or their ID here
- Other columns are optional and can be added as needed
List of headers and their values:
| Column Name in Table | Value | | --- | --- | | First Name | Contact's first name | | Last Name | Contact's last name |
| LinkedIn ID | LinkedIn URL/ID (required field) | | Email | Email address | | Company | Company name | | Position | Job
title | | Website | Company domain | | Headline | Profile headline | | Location | Contact's location |
Example of a filled table:
| First Name | Last Name | LinkedIn ID | Email | | --- | --- | --- | --- | | John | Doe | john-doe-123456 |
john.doe@example.com |
β
Step 2. Setting up Google Apps Script
1. Create a Grinfi API Key here.
2. Find the List UUID where contacts will be imported (go to CRM β Lists, click "..." next to the desired list β Copy
List ID)
3. Open your Google Sheet.
4. Rename the sheet to "Leads" (if you use a different name, you must update the line var SHEET_NAME = 'Leads'; in the
code below with your actual sheet name)
5. In the toolbar, go to Extensions β Apps Script.
6. Paste the code snippet below, replacing YOUR_API_KEY and YOUR_LIST_UUID with your actual data.
β
var GRINFI_API_KEY = 'Bearer YOUR_API_KEY';
var LIST_UUID = 'YOUR_LIST_UUID';
var SHEET_NAME = 'Leads';
var FIELD_MAP = {
'First Name': 'first_name',
'Last Name': 'last_name',
'LinkedIn ID': 'linkedin_id',
'Email': 'email',
'Company': 'company_name',
'Position': 'position',
'Website': 'domain',
'Headline': 'headline',
'Location': 'raw_address'
};
function sendLeadToGrinfi(e) {
var sheet = e.source.getActiveSheet();
if (sheet.getName() !== SHEET_NAME) return;
var editedRow = e.range.getRow();
if (editedRow <= 1) return;
if (editedRow !== sheet.getLastRow()) return;
var lastCol = sheet.getLastColumn();
var headers = sheet.getRange(1, 1, 1, lastCol).getValues()[0];
var values = sheet.getRange(editedRow, 1, 1, lastCol).getValues()[0];
var lead = {};
for (var i = 0; i < headers.length; i++) {
var header = headers[i].toString().trim();
var apiField = FIELD_MAP[header];
if (apiField && values[i]) {
lead[apiField] = values[i].toString().trim();
}
}
if (!lead.linkedin_id) return;
var payload = {
lead: lead,
list_uuid: LIST_UUID,
update_if_exists: true,
move_to_list: true
};
var options = {
method: 'POST',
headers: {
'Authorization': GRINFI_API_KEY,
'Content-Type': 'application/json'
},
payload: JSON.stringify(payload),
muteHttpExceptions: true
};
var response = UrlFetchApp.fetch(
'https://leadgen.grinfi.io/leads/api/leads/upsert',
options
);
Logger.log('Row ' + editedRow + ': ' + response.getContentText());
}
Step 3. Set up a Trigger
To ensure the script automatically sends data when a new row is added to the spreadsheet (including when pasting from
other sources), you need to configure a trigger:
1. In Apps Script, open the menu on the left: Triggers
2. Click "+ Add Trigger"
3. Select:
β’ Function: sendLeadToGrinfi
β’ Event source: From spreadsheet
β’ Event type: On edit
4. Click Save
5. Allow access to Google Sheets (an authorization window will appear)
Step 4. Test the Script
1. Go back to the spreadsheet
2. Add a new row with data (make sure to fill in the LinkedIn ID column)
3. Wait 2β5 seconds
4. Open Grinfi β relevant list, and check if the contact from the spreadsheet has appeared
If the contact did not appear:
β’ In Apps Script, open the Execution log and check for errors
β’ Double-check your API Key, List UUID, and Sheet Name.
How It Works (Technically)
1. When a new row is added, the set trigger is activated
2. The script verifies: Is this the correct sheet? Is it a new row? Does it have a LinkedIn ID?
3. The script reads column names from row 1 and matches them to API fields using the mapping table (FIELD_MAP)
4. Sends a request to the Grinfi API (If the contact does not exist, the script creates it; if it already exists, it
updates the data and moves it to the specified list)
5. The contact appears in the specified list
β