Search code examples
phpcurlphp-curlhubspothubspot-api

HubSpot API - Getting contacts modified in the past 2 minutes - Getting contacts that were modified a day ago or more


So my HubSpot account is in Chicago central timezone so I've made sure that the PHP code running is the same as well by setting the default timezone.

I'm trying to retrieve all contacts that were modified in the past 2 minutes.

Currently I'm getting contacts that were modified from 2 days.

I've checked my UNIX timestamp that I'm passing to the "lastmodifieddate" filter and using the operator "GTE" and I've played around with the filter and nothing has changed.

Here is my script: date_default_timezone_set('America/Chicago'); $pastTime = date("m/d/Y h:i:s a", strtotime('-2 minutes'));

$pastUnix = strtotime($pastTime);
echo "UnixTime:". $pastUnix;

$url = 'https://api.hubapi.com/crm/v3/objects/contacts/search';
$filters = [
     [
         "propertyName" => "lastmodifieddate",
         "operator" => "GTE",
         "value" =>  $pastUnix
     ]
 ];

Very curious as to why I'm getting 100 results back from contacts that were modified 2 days ago or more but not contacts I just modified 1 minute ago.

Any help would be appreciated.


Solution

  • Hey if anybody is having this similar issue just want to say that I solved it!

    The "lastmodifieddate" needs to not only be a UNIX time stamp but it needs to also be converted to milliseconds.

    for example, just multiple the timestamp by 1000:

    "value" => $pastUnix * 1000 // Converting to milliseconds