APIs & Integrations

Harshdeep_Khatr
Member

Sales Activity Report

I want to create Sales Activity Kind of report, mechanism of this report is like, on a daily bases we use to assign leads to the salesperson, I want to get a list of leads where there has been no action taken after assignment, also on old assign leads, there might be a reminder set, so If those leads also not contacted as per stipulated time, I want to get list of them as well.

In nutshell, I want to ensure whatever leads assign to sale person should always be contacted within 24 hours and if that is not done, I get a report for those leads and sales person name.

Which API can provide me such data?

0 Upvotes
10 Replies 10
cbarley
HubSpot Alumni
HubSpot Alumni

Sales Activity Report

Hey @Harshdeep_Khatri, happy to clarify!

  1. I'm looking to just get contacts that have been modified from now until the date I included in my code. I did not include an initial vid or time offset because my first call to the endpoint would be from the most recently modified contact first, paging back to the oldest modified. That initial call I made would inherently not need a vid or time offset. All subsequent calls would, though. If you're paging from oldest modified to newest modified, then it would make sense to include vid and time offset, but for my case, it didn't make sense to do so. The way time and vid offset work is that they work together to create a sort of "marker" on at which contact your calls left off.
  2. I have the converted date property there so I can decide how far back I want to go. I'm comparing the date for however far back I want to go to the addedAt property which returns the time that the contact was modified at. If addedAt is greater than the time I'm looking for and has-more is true (e.g. there are still contacts I need to return) I'll continue paging and pushing contacts to the array. The reason I do this is because If I just compared time offset to my desired date I want to page to, I might miss out on some contacts, or return too many. For example, if I make requests of 100 contacts and the time offset is one second before my convertedDate value, the next request would be made for the next 100 contacts, and it's not likely that all 100 will actually have been updated within my desired timeframe. Some contacts may have been updated longer ago.

I hope this helps clear up some things but let me know if you have more questions

*EDIT

As a question for you, are you looking for a particular thing when you're using this endpoint? If so, you might want to check out webhooks if you're looking for a change on a particular property.

We also recommend using the recently modified contacts endpoint frequently, with not that many contacts returned as we can only go back 30 days, and the max amount of contacts that can be returned is 10,000

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Sales Activity Report

Hi @Harshdeep_Khatri, I tested some code on my own account using NodeJS, and while it was a smaller sample size (100 contacts), I was able to get the exact number of contacts that were modified in app (by creating a filter of the last modified date property):

My Program:

Screenshot

Captured with Lightshot

My Account:

Screenshot

Captured with Lightshot

Make sure you're handling the date properly and that the timestamp for your since variable is correctly returning the time from 24 hours ago. I'm not too familiar with PHP/curl so I can't speak to the viability of your code, but if you're curious to see how I wrote mine you can go to this codepen project: https://codepen.io/cbarley10/pen/rQQdva

0 Upvotes
Harshdeep_Khatr
Member

Sales Activity Report

@Connor_Barley Fortunately with God's grace I understand all the programming languages, from your code I can see some of the basic difference like.

  1. For the first attempt, you are not passing vid-offset and time-offset, which you are not passing, can you please explain why? because if we don't pass time before 24 hours, how the system will know that it needs to pool record based on that condition during the initial call?
  2. Also, you are comparing each time item added date with converted date, why that is required? if I am passing time offset already in URL, the system should filter data accordingly and pass only those data which fulfill the condition.
  3. Rest of the code almost has no difference

It looks like, API is working a bit differently then I am actually thinking based on documentation.

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Sales Activity Report

hi @Harshdeep_Khatri, sorry for the delay - it was a holiday here in the US so I wasn't online until today. Can you reply with your Hub ID?

I am looking through my own account and using this request but am able to get recently modified contacts without issue. It's likely an implementation issue rather than a problem with the endpoint since I can't reproduce it. Make sure you also have some sort of logic for handling the timeOffset and making requests only unless the time offset is less than 24 hours ago.

One other thing is that the timeOffset parameter should be used to just offset your requests and page back through your contacts . It should be "Used in conjunction with the vidOffset parameter to page through the recent contacts. Every call to this endpoint will return a time-offset value". A time offset on your original request shouldn't be used because that request will return a response of the recently modified contacts, which will also include a time offset to check to see if you need to keep paging backward. Another note is that vid is a unique identifier for the contact's ID and is not sequential, so you should also start without a vidOffset specified.

0 Upvotes
Harshdeep_Khatr
Member

Sales Activity Report

our hub id is 502973

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Sales Activity Report

Hi @Hardeep_Joshi, can you clarify what's wrong? Are you looking to find only contacts that were changed in the last 24 hours? And the API isn't returning the correct result?

0 Upvotes
Harshdeep_Khatr
Member

Sales Activity Report

Yes, your assumptions are right, I just want to get all contact created or modified in last 24 hours, but this API keep returning entire contact data set. I have shared code as well for better understanding.

0 Upvotes
Harshdeep_Khatr
Member

Sales Activity Report

@Connor_Barley Any update?

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Sales Activity Report

Hi @Harshdeep_Khatri, you shouldn't need to use the API for this type of filtering capability. You should be able to create a filtered list of contacts in-app whose "owner assigned date" is known or is a certain value, and "last contacted" property is unknown to pull a list of all contacts that have yet to be contacted but have indeed been assigned an owner.

With the API, this would be more complex. You could use the get all contacts endpoint to get all contacts, then filter contacts using the same properties I described above and do some math to figure out if the contact had been contacted within 24 hours or not. You could also leverage this endpoint instead https://developers.hubspot.com/docs/methods/contacts/get_recently_updated_contacts

That said, I think the better option would be to do this in-app

0 Upvotes
Harshdeep_Khatr
Member

Sales Activity Report

I have tried suggested API, but it is behaving abnormally. As per documentation I am passing initially vidOffset = 1, count=100 and timeOffset = timestamp of last 24 hours, also changing vidOffset and timeOffset with newly provided API, but it loops me through almost entire contact list not just returning contact created or modified in last 24 hours.

$since=strtotime('-24 hours', time())*1000;
$offset=1;

while(1)
{

	$url = 'https://api.hubapi.com/contacts/v1/lists/recently_updated/contacts/recent?hapikey='.$apikey.'&count=100&vidOffset='.$offset.'&timeOffset='.$since;
	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$result = curl_exec($ch);
	$data1 = json_decode($result, true);
	
	foreach ($data1['contacts'] as $row){
		// my logic
	}
	
	$offset = $data1['vid-offset'];
	$since = $data1['time-offset'];
			
	if($data1['has-more']===false) break;
}
0 Upvotes