Connecting to Google Sheets
This article explains how to connect LeadByte to Google Sheets for lead transfer, covering setting up a direct post delivery to send leads from LB to Sheets and it also goes over using webhooks with Google Apps Script to send over event data (sold leads). It provides step-by-step instructions for setup, authorization, mapping fields, deploying web apps, and troubleshooting common questions.
This article aims to take you through the process of being able connect to a Google Sheet so you can transfer leads to it. Transferring leads to a Google Sheet is most commonly used by clients where the Buyer does not have an API but operate via Google Sheets.
We will cover:
1. Sending Lead Data using a Google Sheet Delivery where we have a native integration
2. Sending event data (like Lead Sold) to a Google Sheet using a Webhook
Creating a Google Sheet Delivery
When you add a new Delivery, you need to select the Action "Direct Post" using the Method "Google Sheets". By default, the simplified method is selected (recommended) and the URL will be added. We advise that you do not change the URL.
Once you have done this, you will have the option to "Authorise Access" (connect) under the Google Sheets Integration section. Here follows the steps to connect to a Google Sheet and send a test lead:
Here are the steps
1. Authorise to get the code.
2. Copy the code into the Delivery field "Authorisation Code".
3. Enter in the Google Sheet ID
4. Ensure your Input Fields are mapped correctly to your Google column headers (output Fields)
5. Test the Delivery.
6. Check the test request has arrived.
Sending event data (like Lead Sold) to a Google Sheet via Webhooks
This guide explains how to automatically send LeadByte webhook data into a Google Sheet using a Google Apps Script Web App. Once set up, every webhook Lead will be added as a new row in your spreadsheet.
You will:
- Create a Google Sheet
- Add a Google Apps Script to receive webhook data
- Deploy the script as a public Web App
- Copy the Web App URL
- Create Your LeadByte Webhook
#1 Create a Google Sheet
1. Go to https://sheets.google.com
2. Create a new spreadsheet
3. (Optional) Rename the first tab to Leads
4. Add column headers, e.g.: Buyer | Buyer ID | First Name | Last Name | Email | Phone | ZIP |
#2. Add the Google Apps Script
1. Inside your Google Sheet, click:
2. Extensions → Apps Script
3. Delete any existing code
4. Paste this code:
function doPost(e) {
try {
var body = e.postData && e.postData.contents ? e.postData.contents : null;
if (!body) {
return ContentService
.createTextOutput(JSON.stringify({ success: false, error: "No POST data" }))
.setMimeType(ContentService.MimeType.JSON);
}
var data = JSON.parse(body);
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Leads"); // Or change to your tab name
var row = [
new Date(),
data.buyer || "",
data.buyer_id || "",
data.first_name || "",
data.last_name || "",
data.email || "",
data.phone || "",
data.zip || ""
];
sheet.appendRow(row);
return ContentService
.createTextOutput(JSON.stringify({ success: true }))
.setMimeType(ContentService.MimeType.JSON);
} catch (err) {
return ContentService
.createTextOutput(JSON.stringify({ success: false, error: err.message }))
.setMimeType(ContentService.MimeType.JSON);
}
}
4. Save
#3. Deploy the Script as a Web App
This creates a URL LeadByte can POST data to.
1. Click Deploy → New deployment
2. Select Web app
3. Configure as follows:
| Setting | Value |
| Execute as | Me |
| Who has access | Anyone |
| Description | Webhook |
4. Click Deploy
5. Copy the Web App URL
6. You will be prompted to Authorize the script
- Click Advanced → Go to Untitled Project (unsafe)
- Click Allow
4. Copy the Web App URL (very important)
It will look like this
https://script.google.com/macros/s/AKfycbX.../exec
5. Create Your LeadByte Webhook
Inside LeadByte you need to create your Webhook.
1. Admin > Techhub > Webhooks
2. Create Webhook
3. Webhook version should be 1.6 with Custom Payload
4. Set:
- Request Type: POST
- Endpoint URL: paste your Web App URL
- Content Type: application/json
5. Add your JSON body, e.g.:
{
"buyer": "[buyername]",
"buyer_id": "[buyer]",
"first_name": "[firstname]",
"last_name": "[lastname]",
"email": "[email]",
"phone": "[phone1]",
"zip": "[postcode]"
}6. Ensure the HTTP Status for success is 302. Google Web Apps first return a 302 Redirect.
7. Test and ensure data is appearing in GoogleSheet.
Q&A
Q. How do I get the spreadsheet ID?
A. It's in the URL as per the video
Q. How do I make sure the data is mapped correctly to my Google Sheet column headers?
A. Make sure the LeadByte Output Fields in the Delivery match the Google Sheet column headers
Q. How do I push the data to a specific tab in the Google Sheet
A You should use the Spreadsheets tab name field on the Delivery to enter in the Field tab name
Comments