Skip to content

Instantly share code, notes, and snippets.

@mrlynn
Created March 3, 2019 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrlynn/94c63489014795aec4af34f874536531 to your computer and use it in GitHub Desktop.
Save mrlynn/94c63489014795aec4af34f874536531 to your computer and use it in GitHub Desktop.
Google Sheets Script to Remove Events from a MongoDB Database
/****
* Delete the events from the Calendar and remover the eventID Reference from the sheet - wipeout.
****/
function removeEventsFromMongoDB() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName("Events");
var headerRows = 1; // Number of rows of header info (to skip)
var range = sheet.getDataRange();
var numRows = range.getNumRows();
var data = range.getValues();
for (var i=headerRows; i<numRows; i++) {
// Cells are 1 indexed
var eventIdCell = range.getCell(i+1, columns.event_id+1);
// Make a POST request with form data.
var formData = {
'name': data[i][columns.desc],
'location': data[i][columns.loc],
'date_start': data[i][columns.date_start],
'date_end': data[i][columns.date_end],
'status': data[i][columns.status],
'owner': data[i][columns.owner],
'type': data[i][columns.type],
'event_id': data[i][columns.event_id]
};
var options = {
'method' : 'post',
'payload' : formData
};
var insertID = UrlFetchApp.fetch('https://webhooks.mongodb-stitch.com/api/client/v2.0/app/stitch-sheets-zkvuv/service/sheets/incoming_webhook/remove', options);
eventIdCell.setValue(""); // Insert the new event ID
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment