Skip to content

Instantly share code, notes, and snippets.

@bmcbride
Created March 28, 2018 17:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bmcbride/d5e6677409cd6da5d4cffeb1307a3609 to your computer and use it in GitHub Desktop.
Save bmcbride/d5e6677409cd6da5d4cffeb1307a3609 to your computer and use it in GitHub Desktop.
Google Apps Script for exporting CSV files from the Fulcrum Query API to a Drive folder
/**
Title: Google Apps Script for exporting CSV files from the Fulcrum Query API to a Drive folder
Notes: Be sure to manually run the exportData() function at least once to authorize the script. Set a timed trigger to automate exports.
Author: Bryan R. McBride
**/
var fulcrumToken = "abcdefghijklmnopqrstuvwxyz";
var fulcrumFormName = "My App";
var filesFolder = "1_NGfsxszanv2evVJgfKMXxmU54SZ92FW";
function exportData() {
var query = "SELECT * FROM \"" + fulcrumFormName + "\" WHERE _server_updated_at >= NOW() - '1 day'::INTERVAL ORDER BY _server_updated_at DESC";
var url = "https://api.fulcrumapp.com/api/v2/query/";
var options = {
"method": "POST",
"headers": {
"X-ApiToken": fulcrumToken,
"Accept": "application/json"
},
"contentType": "application/json",
"payload" : JSON.stringify({
"q": query,
"format": "csv"
})
};
var csvFile = UrlFetchApp.fetch(url, options);
var date = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd");
DriveApp.getFolderById(filesFolder).createFile(date+".csv", csvFile, MimeType.CSV);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment