I've been trying to query journal entries from QuickBooks Online using the Method API. I've created a sort of generic function to query the table in Google Apps Script and copy the data to a sheet.
This code works fine for other tables (like Account, Invoice, etc), but for some reason doesn't work for either JournalEntry or JournalEntryLines. The error is just that the response is blank. Ultimately I want to be able to create new journals as well as query them.
Any idea what's going on here? Why is the response blank?
function outputTable() {
var tblName = 'JournalEntry';
var pageCount = 5;
var url = 'https://rest.method.me/api/v1/tables/';
var addon = '?skip=1';
url = url + tblName + addon;
var sheetName = 'Method_' + tblName;
var sheet = SpreadsheetApp.openById(spreadsheetId).getSheetByName(sheetName);
var headersDone = false;
var headers = {
'Authorization': methodApiKey
};
var options = {
'method': 'get',
'headers': headers,
'muteHttpExceptions': true
};
sheet.clear();
var allRows = [;
do {
var response = UrlFetchApp.fetch(url, options);
if(response.getResponseCode() === 200) {
var tableData = JSON.parse(response.getContentText());
if (headersDone == false) {
headersDone = true;
var headerRow = [;
for (var key in tableData.value[0]){
headerRow.push(key);
}
allRows.push(headerRow);
}
for (var i = 0; i < tableData.value.length; i++) {
var thisRow = tableData.value[i];
var rowData = [;
for (var key in thisRow) {
rowData.push(thisRow[key]);
}
allRows.push(rowData);
}
// Append rows within the loop
sheet.getRange(sheet.getLastRow() + 1, 1, allRows.length, allRows[0].length).setValues(allRows);
// Flush changes
SpreadsheetApp.flush();
// Clear allRows for the next iteration
allRows = [;
} else {
Logger.log('Error: ' + response.getResponseCode() + ' - ' + response.getContentText());
}
pageCount = pageCount - 1;
url = tableData.nextLink;
} while ((tableData.nextLink != null) && pageCount != 0);
}