Skip to content

Instantly share code, notes, and snippets.

@Suleman-Elahi
Last active June 26, 2024 06:04
Show Gist options
  • Save Suleman-Elahi/e412eec49beb608546e28756e619cc23 to your computer and use it in GitHub Desktop.
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
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');
}
@Suleman-Elahi
Copy link
Author

@Suleman-Elahi
Copy link
Author

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 🙂👍

  1. Make a Copy of the Google Sheet template included in the comments of the gist.
    
  2. Deploy the script as web app, get the URL.
    
  3. 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.
    
  4. Publish/Test the workflow.
    
  5. New Contact will now be pushed to the Google Sheet.
    
  6. Enjoy.
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment