Metrics on deals, companies, contacts via API

Hello all :slightly_smiling_face:

Can someone please help out in how i can get only the count of objects by a owner e.g.:

- count of deals open, closed by an owner per day for the past 7/30 days

- count of how many companies were added

- count of how many contacts were added

It seems to get any form of count, we have to iterate through all the results but hoping there is a quicker method.

Thanks

Hello @MPanti,

Thank you for your question. I would be happy to help!

First and foremost, let’s begin by examining an example with a report. Once we have covered the steps involved, you can conveniently replicate the same process with other objects of interest. This approach will ensure an efficient and uniform experience as you navigate through the various tasks.

Report that counts the number of contacts by contact owner during a specific timeframe

Please let me know if this is what you are looking for. Feel free to reach out if you have any other questions or require additional assistance.

Best regards,

Diana

Sorry i should have specified that i want this information via the API. Thanks

Hi @MPanti

Thank you for letting me know. Now that you have changed the title of the question, I will move this conversation to the appropriate forum.

Allow me to consult a few HubSpot experts for some insights: Hello @mangelet, @Mike_Eastwood, @HubDoPete! Would you kindly share any recommendations for @Shepp?

We deeply value your contributions!

Thanks,

Diana

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.