Monday to Google Sheets Board Download - Query no longer working

Hey All,

The script I was using to send a board’s data into a Google Sheet has stopped working suddenly. I presume this is because of the API changes.
I am not a developer and wondered if anyone can assist me in trying to repair the code so that the query works again.

The below code in bold is where the error is occurring, stating the following “TypeError: Cannot read properties of undefined (reading ‘boards’) downloadMondayBoard”

// Add column headers if not added yet
if (headers.length <= 2) {
data.data.boards[0].items_page_by_column_values[0].column_values.forEach(function(column) {
headers.push(column.title);
});
sheet.appendRow(headers);
}

Hello there @jholdstock and welcome to the community!

I hope you like it here :muscle:

It looks like this part of the script is just reading a response you get.

What is the exact query you are using and what response do you get from it?

Looking forward to hearing from you :slightly_smiling_face:

Cheers,
Matias

Hey @Matias.Monday, thanks for the reply!

So below is the full script, with the API etc removed. Let me know if you need anything else. I am not a developer so my knowledge is sadly quite limited here.

function downloadMondayBoard() {
var apiKey = “xxxxx”;
var boardId = “xxxxxxx”;

var url = “https://api.monday.com/v2”;

var options = {
method: “POST”,
headers: {
“Authorization”: apiKey,
“Content-Type”: “application/json”
},
payload: JSON.stringify({
query: "query { boards(ids: " + boardId + “) { name, items { id, name, column_values { title, text } } } }”
})
};

var response = UrlFetchApp.fetch(url, options);
var data = JSON.parse(response.getContentText());

var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

// Clear existing data
sheet.clearContents();

// Write headers
var headers = [“Item ID”, “Item Name”];
data.data.boards[0].items[0].column_values.forEach(function(column) {
headers.push(column.title);
});
sheet.appendRow(headers);

// Write item data
data.data.boards[0].items.forEach(function(item) {
var rowData = [item.id, item.name];
item.column_values.forEach(function(column) {
rowData.push(column.text);
});
sheet.appendRow(rowData);
});
}

Hello again @jholdstock,

You are using a deprecated query boards -> items

Instead you need to use boards -> items -> items_page as explained here.

I hope that helps :grin:

Cheers,
Matias