Created
July 27, 2021 11:23
-
-
Save jpvalery/04774511ba93c6ad10f294a68dadbaee to your computer and use it in GitHub Desktop.
A Google Sheet AppScript to sync the sheet with a Customer.io Collection
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
//Customer.io Collections Sync w/ Automated Sync | |
function updateCollection() { | |
var api_key = "[YOUR_APP_API_KEY]"; | |
var collection_id = "[THE_COLLECTION_ID]"; | |
var url = "https://beta-api.customer.io/v1/api/collections/" + collection_id; | |
var data = { | |
name: SpreadsheetApp.getActiveSheet().getName(), | |
url: SpreadsheetApp.getActiveSpreadsheet().getUrl(), | |
}; | |
var payload = JSON.stringify(data); | |
var headers = { | |
"Content-Type": "application/json", | |
Authorization: "Bearer " + api_key, | |
}; | |
var options = { | |
method: "put", | |
contentType: "application/json", | |
headers: headers, | |
payload: payload, | |
}; | |
var response = UrlFetchApp.fetch(url, options); | |
Logger.log(response.getContentText()); | |
} | |
//add a menu item to the spreadsheet | |
function onOpen() { | |
var ui = SpreadsheetApp.getUi(); | |
ui.createMenu("Customer.io") | |
.addItem("Sync Collection to Customer.io", "updateCollection") | |
.addToUi(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment