Filtering deals integration on google sheets through API


#1

Hello,
I am trying to make a function to pull the deals from Hubspot and write them in google sheets. I found some code already done which I have adapted to my needs, the code works but after a while will start getting the 429 error or it will exceeds google scripts good practices (it takes longer than 30 seconds) whenever I run the script. The issue seems to be the huge amount of data that exceeds both the hubspot limits and google scripts good practices. Is there a way to filter deals to make the data amount smaller (for example deals from a specific pipeline only).

Thanks
(code bellow)

function getDeals() {
// Authentication
var service = getService();
var headers = {headers: {'Authorization': 'Bearer '+ service.getAccessToken()}};

// Prepare pagination
// Repeat the request untill all results.
var keep_going = true;
var offset = 0;
var deals = Array();
while(keep_going) {

   // Get all deals (name and close date)  
   var url = API_URL + "/deals/v1/deal/paged?properties=dealname&properties=closedate&limit=250&offset="+offset;
   var response = UrlFetchApp.fetch(url, headers);
   var result = JSON.parse(response.getContentText());
   keep_going = result.hasMore;
   offset = result.offset;
  
   // For each deal name and close date
   result.deals.forEach(function(deal) {
      var name = (deal.properties.hasOwnProperty("dealname")) ? deal.properties.dealname.value : "unknown";
      var closedate = (deal.properties.hasOwnProperty("closedate")) ? deal.properties.closedate.value : "unknown";
      deals.push([name,closedate]);
   });
}
return deals;
}

#3

Hi Nazare,

There's presently no endpoint that lets you GET all deals under a specific pipeline. What you could do if you need to make the data amount smaller is use the limit parameter highlighted in this article: https://developers.hubspot.com/docs/methods/deals/get-all-deals

You could then use the offset in your first request in subsequent requests to get the remaining deals.