I am not getting all property history for the deals that I am retrieving in the following function. Any help would be appreciated.
function getDeals() {
// Prepare authentication to Hubspot
var service = getService();
var headers = {headers: {‘Authorization’: 'Bearer '+ service.getAccessToken()}};
// Prepare pagination
// Hubspot lets you take max 250 deals per request.
// We need to make multiple request until we get all the deals.
var keep_going = true;
var offset = 0;
var deals = Array();
while(keep_going) {
// We’ll take a few properties from the deals: the stage & the amount of the deal, and what else?
var url = API_URL + “/deals/v1/deal/paged?properties=dealstage&properties=dealname&properties=amount&limit=250&includePropertyVersions=true&offset=”+offset; // add additional data fields we want
var response = UrlFetchApp.fetch(url, headers);
var result = JSON.parse(response.getContentText());
// Are there any more results, should we stop the pagination
keep_going = result.hasMore;
offset = result.offset;
// For each deal, we take the stageId & amount, and what else?
result.deals.forEach(function(deal) {
var stageId = (deal.properties.hasOwnProperty(“dealstage”)) ? deal.properties.dealstage.value : “unknown”;
var dealName = (deal.properties.hasOwnProperty(“dealname”)) ? deal.properties.dealname.value : “unknown”;
var dealTimeStamp = (deal.properties.hasOwnProperty(“dealname”)) ? deal.properties.dealname.timestamp : “unknown”; // add additional data fields we want
var amount = (deal.properties.hasOwnProperty(“amount”)) ? deal.properties.amount.value : 0;
var versions = (deal.properties.hasOwnProperty(“dealstage”)) ? deal.properties.dealstage.versions : “unknown”;
deals.push([stageId,dealName,dealTimeStamp,amount,versions]); // add additional data fields we want
});
}
return deals;
}
Hey @yokomeshi
If you want to get the history of a property, you would replace properties= with propertiesWithHistory=
Thanks, Dennis!