Last active
June 26, 2024 06:04
-
-
Save Suleman-Elahi/e412eec49beb608546e28756e619cc23 to your computer and use it in GitHub Desktop.
A Simple Google Apps Script to Push Newly Added Contacts from GoHighLevel Automations to Sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doPost(e) { | |
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Contacts'); //Change Sheet Name | |
var jsonData = JSON.parse(e.postData.contents); | |
var first_name = jsonData.first_name || ''; | |
var last_name = jsonData.last_name || ''; | |
var full_name = jsonData.full_name || ''; | |
var email = jsonData.email || ''; | |
var phone = jsonData.phone || ''; | |
var tags = jsonData.tags || ''; | |
var country = jsonData.country || ''; | |
var state = jsonData.state || ''; | |
var city = jsonData.city || ''; | |
var postalCode = jsonData.postal_code || ''; | |
var fullAddress = jsonData.full_address || ''; | |
var customDataValues = []; | |
if (jsonData.customData) { | |
for (var key in jsonData.customData) { | |
if (jsonData.customData.hasOwnProperty(key)) { | |
customDataValues.push(jsonData.customData[key]); | |
} | |
} | |
} | |
var row = [ | |
first_name, last_name, full_name, email, phone, tags, country, state, city, postalCode, fullAddress | |
].concat(customDataValues); | |
sheet.appendRow(row); | |
return ContentService.createTextOutput('Data received and added to sheet'); | |
} |
Send New Contact to Google Sheet from GHL using Automation. I created this for personal use and now sharing it here if someone else needs it 🙂👍
-
Make a Copy of the Google Sheet template included in the comments of the gist.
-
Deploy the script as web app, get the URL.
-
Use trigger "Contact Created". Add "Webhook" action in next step and add the Apps Script URL in the webhook's URL field . In Custom Data, add the custom fields you want to include in the the sheet row.
-
Publish/Test the workflow.
-
New Contact will now be pushed to the Google Sheet.
-
Enjoy.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's the ready-made Google Sheet Template that you can use: https://docs.google.com/spreadsheets/d/17RYzjKmMetnNew357UaMsn30FpyJOu3F1_U8WnV5k5Q/edit?gid=0#gid=0