I am working on setting up a Google App Script to help pull data on a schedule into a Sheet (similar to this other community post).
In this case though I have two views setup (one for assets and one for tickets). I think I have something that might work but this is well outside my wheelhouse and was wondering if anyone in the community has done this/could check my script.
This one is for tickets and I’d just swap the view IDs, module, product ID, and sheet name:
function pullTicketsPost() {
const API_KEY = 'YOUR_API_KEY';
const VIEW_ID = 'YOUR_TICKET_VIEW_ID';
// The Product ID for the Tickets module
const PRODUCT_ID = '88df910c-91aa-e711-80c2-0004ffa00010';
// URL targeting the Tickets module with a high result count to minimize paging
const URL = 'https://bisd303.incidentiq.com/api/v1.0/tickets?$s=5000';
// Constructing the payload to filter by the specific View ID [1]
const payloadData = JSON.stringify({
"ProductId": PRODUCT_ID,
"Filters": [
{
"Facet": "View",
"Id": VIEW_ID
}
]
});
const options = {
"method": "POST",
"headers": {
"Authorization": "Bearer " + API_KEY,
"Content-Type": "application/json",
"Accept": "application/json"
},
"payload": payloadData,
"muteHttpExceptions": true
};
try {
const response = UrlFetchApp.fetch(URL, options);
const json = JSON.parse(response.getContentText());
// Access the array of tickets in the response [6, 7]
const data = json.Items;
if (!data || !Array.isArray(data)) {
throw new Error("No ticket data found. Verify your View ID and API Key.");
}
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName("Tickets");
if (!sheet) {
throw new Error("Please create a tab named 'Tickets' in your spreadsheet.");
}
sheet.clear();
if (data.length > 0) {
const headers = Object.keys(data);
const rows = data.map(item => headers.map(header => item[header]));
sheet.getRange(1, 1, 1, headers.length).setValues([headers]);
sheet.getRange(2, 1, rows.length, headers.length).setValues(rows);
SpreadsheetApp.getUi().alert("Imported " + rows.length + " tickets successfully!");
} else {
SpreadsheetApp.getUi().alert("The selected view returned no tickets.");
}
// Timestamp for the last update [8]
sheet.getRange("Z1").setValue("Last Updated: " + new Date().toLocaleString());
} catch (e) {
Logger.log(e.toString());
SpreadsheetApp.getUi().alert("Error: " + e.message);
}
}
Any help and insight is appreciated.

