I’m working on pulling Hubspot deal info into Google Sheets. I followed a guide online but hit a snag. When I run the script, I get this error: “Exception: The number of columns in the data does not match the number of columns in the range. The data has 0 but the range has 2.”
Here’s a simplified version of what I’m trying:
function fetchHubspotDeals() {
const API_KEY = 'your_api_key_here';
const API_ENDPOINT = 'https://api.hubapi.com/deals/v1/deal/paged';
const options = {
headers: { Authorization: `Bearer ${API_KEY}` },
muteHttpExceptions: true
};
const response = UrlFetchApp.fetch(API_ENDPOINT, options);
const data = JSON.parse(response.getContentText());
// Process and write data to sheet
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sheet.getRange(1, 1, data.deals.length, 2).setValues(data.deals.map(deal => [deal.id, deal.properties.amount.value]));
}
Any ideas on what might be causing this error or how to fix it? I’m pretty new to API stuff, so I might be missing something obvious. Thanks for any help!