Skip to content

Instantly share code, notes, and snippets.

@tariqhamid
Created June 18, 2016 13:02
Show Gist options
  • Save tariqhamid/4869aa8279f5cbc6de7f404a9da25f0e to your computer and use it in GitHub Desktop.
Save tariqhamid/4869aa8279f5cbc6de7f404a9da25f0e to your computer and use it in GitHub Desktop.
Send Google Apps Script data to a Cloudant CouchDB database.
//Send Google Apps Script data to a Couch DB database
function syncWithDB(data){
var username = ScriptProperties.getProperty('user');
var password = ScriptProperties.getProperty('pass');
var url = 'https://[username].cloudant.com/[dbname]/_bulk_docs';
var params = {
"method" : "post",
"contentType":"application/json",
"validateHttpsCertificates" :false,
"payload" : JSON.stringify(data),
"headers":{
"Authorization": "Basic " + Utilities.base64Encode(username + ":" + password)
}
}
return UrlFetchApp.fetch(url, params);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment