Hello,
I am looking to get a count of deals based on criteria using API.
The criteria being pipeline and create date.
Is there API documentation where this is laid out clearly?
I see on the Deal end points Get /crm/v3/objects/deals “Read a page of deals. Control what is returned via the properties query param.”
I also know you can search /crm/v3/objects/deals/search
Please let me know.
Thanks.
I have gotten the code to here:
const axios = require('axios');
exports.main = async (event, callback) => {
const token = process.env.Secret;
async function getDealCount() {
const startDateLocal = new Date(2023, 0, 1);
const endDateLocal = new Date(2023, 0, 31, 23, 59, 59);
// Convert the local dates to Mountain Time and then back to UTC
const startDateMT = new Date(startDateLocal.toLocaleString("en-US", {timeZone: "America/Denver"}));
const endDateMT = new Date(endDateLocal.toLocaleString("en-US", {timeZone: "America/Denver"}));
// Convert the dates to Unix timestamps
const startDate = startDateMT.getTime();
const endDate = endDateMT.getTime();
const options = {
method: 'POST',
url: 'https://api.hubapi.com/crm/v3/objects/deals/search',
headers: {
'content-type': 'application/json',
'authorization': `Bearer ${token}`
},
data: {
"filterGroups": [
{
"filters": [
{
"propertyName": "pipeline",
"operator": "EQ",
"value": "Pipeline ID"
},
{
"propertyName": "createdate",
"operator": "GTE",
"value": startDate.toString()
},
{
"propertyName": "createdate",
"operator": "LTE",
"value": endDate.toString()
}
]
}
],
"properties": ["dealname"],
"limit": 100
}
};
try {
const response = await axios(options);
callback({
outputFields: {
deal_count: response.data.total // Get the total count of deals
}
});
} catch (error) {
throw new Error(error.message);
}
}
getDealCount()
.catch(error => {
console.error(error);
});
}
However, there is 1 deal missing. The total in HubSpot is 52, but this code returns 51. I updated the time zone. Any other ideas on how to get the correct number of deals?