Created
September 20, 2016 04:08
-
-
Save shingorow/17355e86d875c90eadc0249214def078 to your computer and use it in GitHub Desktop.
Convert Spreadsheet to CSV and send data to API.
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 sendListToApi() { | |
var props, ssId, sheetName, url, params, ss, sheet, range, values, csv; | |
props = PropertiesService.getScriptProperties(); | |
ssId = props.getProperty('ssId'); // Spreadsheet ID | |
sheetName = props.getProperty('sheetName'); //Sheet Name | |
url = props.getProperty('url'); // API URL | |
ss = SpreadsheetApp.openById(ssId); | |
sheet = ss.getSheetByName(sheetName); | |
range = sheet.getDataRange(); | |
values = range.getDisplayValues(); | |
// Convert range to CSV text. | |
csv = values.map(function(v, i, arr) { | |
return v.join(','); | |
}).join('\n'); | |
params = { | |
method: 'post', | |
payload: csv, | |
contentType: 'text/csv' | |
} | |
UrlFetchApp.fetch(url, params); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment