Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.