I. Setup

To create a webhook with Google Sheets, first, you will need to create a new spreadsheet, and open up the script editor:

This will take you to a text editor, where you can insert any sort of script of your own.

In this editor, you will need to insert the code, which can be found at the bottom of the article. Save the document after you paste the code. The final result should look like the following:

This is optional but you can also add names to the columns of the spreadsheet.

After you’re at the script editor page, paste the code for the webhook, save the project, select “populateHeaders” as the function to run, and then Run the code.

This will fill in the column names for your Google sheet document.

The first time you do this, you will be asked to sign in with your Google account and will be warned that this is not an official Google application. Agree with the warnings and authenticate yourself.

II. Connecting the Spreadsheet to Expandi

Now, to connect the webhook to Expandi, you have to Deploy it as a web app:

Make sure to allow access for Anyone.

After pressing Deploy, you will be given a Web App URL, which you’ll need to add to Expandi.

Next, go to Expandi > Webhooks > Add a webhook:

When you click on Add a new hook a pop-up screen will appear.

  1. You should fill in a name for your webhook

  2. You should choose the event you want your hook to be triggered

  3. Enter the URL you copied earlier.

  4. You should choose the campaign for which you want this webhook to be triggered (you choose from your existing campaigns).

    After clicking “Create New Web Hook”, simply set it to Active using the slider and you are ready to go.

Push webhook manually

A new feature that Expandi has is to manually push people through a webhook. You can do it in two ways - either select the people you want to push or apply filters and push everyone who matches those filters.

You can find this export feature if you go to the sidebar and press Search, Campaign or My Network.

Then if you select the search, the campaign or just go to your network, you will see a button Actions in the top right corner, next to the Filters. Please press Actions and select Export. There you will be able to choose if you want to Export selected through webhook (for the leads you selected in the list) or if you want to Export filtered contacts to webhook (for the leads filtered in the list). You just have to choose one of these options and the webhook will be triggered manually.

Code for Google Sheets:

var postDataList = [];
var waiting = 0;

/ Receive Expandi Webhooks in Google Sheets /
// Below function could be ran to populate the header columns
function populateHeaders(hook_load) {
if(hook_load === undefined) {
hook_load = {
'hook': {
'id': 62,
'li_account': 30,
'name': 'Google Sheets Test',
'event': 'linked_in_messenger.new_contact'
},
'contact': {
'id': -1,
'first_name': 'Example First Name | can be null',
'last_name': 'Example Last Name | can be null',
'tags': [
'tag_1',
'tag_2'
],
'sales_nav_tags': [
'sales_nav_tag_1',
'sales_nav_tag_2'
],
'phone': '0800-EXAMPLE-900 | can be null',
'address': 'Exampletown | can be null',
'object_urn': 12345678,
'company_name': 'Example Inc. | can be null',
'job_title': 'Example Job Title | can be null',
'profile_link': 'www.example.com | can be null',
'image_link': 'www.example.com/picture.jpg | can be null',
'email': 'example@example.com | can be null'
},
'messenger': {
'contact_status': 'New Contact',
'conversation_status': 'Awaiting Reply',
'li_account': 30,
'new_messages': false,
'message': null,
'connected_at': 'The time of becoming connection | can be null',
'campaign_instance': 'Example campaign instance name | can be null',
'note': 'Note you have about your example contact | can be null'
}
};
}
var sheet = SpreadsheetApp.getActiveSheet();
var last_row = Math.max(sheet.getLastRow(),1);
sheet.insertRowAfter(last_row);
var headers_row = [];
headers_row.push('timestamp');
var hook_load_keys = Object.keys(hook_load)
for (i = 0; i < hook_load_keys.length; i++) {
var inner_object = hook_load[hook_load_keys[i]]
var inner_object_keys = Object.keys(inner_object)
for (k = 0; k < inner_object_keys.length; k++) {
if (inner_object_keys[k] == "placeholders") {
var placeholders = Object.keys(inner_object[inner_object_keys[k]])
for (p = 0; p < placeholders.length; p++) {
headers_row.push(hook_load_keys[i] + '_' + inner_object_keys[k] + '_' + placeholders[p])
}
} else {
headers_row.push(hook_load_keys[i] + '_' + inner_object_keys[k])
}
}
}
sheet.appendRow(headers_row);
SpreadsheetApp.flush();
};

function doPost(e) {
var sheet = SpreadsheetApp.getActiveSheet();
var last_row = Math.max(sheet.getLastRow(),1);
var hook_load = null;
try {
hook_load = JSON.parse(e.postData.contents);
} catch (error) {
sheet.appendRow(["error","There was an error in this data"]);
return;
}
var hook_load_keys = Object.keys(hook_load)
var new_sheet_row = [];
if (sheet.getLastColumn() == 0) {
populateHeaders(hook_load)
}
var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
new_sheet_row.push(new Date());
placeholders_to_add = []

headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
for (h in headers){
for (i = 0; i < hook_load_keys.length; i++) {
var inner_object = hook_load[hook_load_keys[i]]
var inner_object_keys = Object.keys(inner_object)
for (k = 0; k < inner_object_keys.length; k++) {
if (inner_object[inner_object_keys[k]] instanceof Object && inner_object[inner_object_keys[k]] != null) {
if (inner_object_keys[k] == "placeholders") {
var placeholders = Object.keys(inner_object[inner_object_keys[k]])
for (p = 0; p < placeholders.length; p++) {
if (headers[h] == hook_load_keys[i] + '_' + inner_object_keys[k] + '_' + placeholders[p]) {
new_sheet_row[h] = placeholders[p]
}
}
} else {
if (headers[h] == hook_load_keys[i] + '_' + inner_object_keys[k]) {
if (Object.prototype.toString.call(inner_object[inner_object_keys[k]]) === '[object Array]') {
new_sheet_row[h] = inner_object[inner_object_keys[k]].join(", ")
} else {
new_sheet_row[h] = inner_object[inner_object_keys[k]]
}
}
}
} else {
if (headers[h] == hook_load_keys[i] + '_' + inner_object_keys[k]) {
new_sheet_row[h] = inner_object[inner_object_keys[k]]
}
}
}
}
}
sheet.appendRow(new_sheet_row);
SpreadsheetApp.flush();
};

Did this answer your question?