Hi,
try this one for counting Contacts and Companies
const axios = require('axios');
exports.main = async (event, callback) => {
let data = JSON.stringify({
"filterGroups": [{
"filters": [{
"value": "1696888800000",
"highValue": "1697493600000",
"propertyName": "createdate",
"operator": "BETWEEN"
}]
}]
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.hubapi.com/crm/v3/objects/contacts/search',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + process.env.Secret
},
data: data
};
axios.request(config).then((response) => {
console.log(response.data)
}).catch((error) => {
console.log(error);
});
}
In response you’ll get value total which represents number of found records.
And to get this valu by day I would run this script daily and save results. If you can’t do that then it’s still posible but thats more coding to iterate and you want to avoid it.
In filters value and highValue are timestamps for dates between which you want to have count of contacts and copmpanies. Those are EPOCH-millisecond timestamp which means you need to multiply UNIX timestamp you get in Javascript by 1000. And remember HubSpot accepts timestamps at midnight.
More about dates formats HubSpot accepts in here.
FYI for datepicker HubSpot accepts this date format YYYY-MM-DD
To count deals use multiple filters in addition to BETWEEN timestamps filter mentioned above
"filterGroups": [{
"filters": [{
"propertyName": "dealstage",
"values": ["dealOpenStageID", "dealOpenStageID"]
"operator": "IN"
}, {
"propertyName": "pipeline",
"value": "pipeLineID",
"operator": "EQ"
}, {
"propertyName": "hubspot_owner_id",
"value": "DealOwnerID",
"operator": "EQ"
}]
}]
You’ll need to find your pipelineID, deal Stage OPEN ID, deal Stage CLOSED ID and DealOwnerID. To do that GET randome deal in target pipeline, stage with each owner you want to get details about.
curl --request GET \
--url 'https://api.hubapi.com/crm/v3/objects/deals/DealID?properties=pipeline%2C%20hubspot_owner_id%2C%20dealstage&archived=false' \
--header 'authorization: Bearer YOUR_ACCESS_TOKEN'
I use Axios library as it’s easier for me to read and troubleshoot.
That should help.