Invalid input JSON when using Contacts/Search endpoint

I’m trying to get a list of contacts last modified after a specified time, but I can’t seem to get it right. When I execute the script, I get the error:

Invalid input JSON on line 1, column 17: Cannot deserialize value of type java.util.HashSetfrom Object value (tokenJsonToken.START_OBJECT)

When I test the post data, it returns as valid JSON:

{"filterGroups":{"filters":{"value":1646144686,"propertyName":"lastmodifieddate","operator":"GT"}}}

I’ve found a few posts both here and on Stack with similar errors, but no solutions.

My code is as such:

$url = "https://api.hubapi.com/crm/v3/objects/contacts/search";
$api_key = 'xxxxxxxxxxxxxxxxxxxxx';

$range = strtotime("-1 hour");

$data = array(
 "filterGroups" => array(
 "filters" => array(
 "value" => $range,
 "propertyName" => "lastmodifieddate",
 "operator" => "GT"
 )
 )
);

$post = json_encode($data);

$ch = curl_init($url . "?hapikey=" . $api_key);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$response = curl_exec($ch);
curl_close($ch);
print_r(json_decode($response));

Any help with what I’m doing wrong would be greatly appreciated.

@JNichel ,

Although it is valid JSON, it is not what the API is expecting.

The filtergroup and filter need to be in arrays. Also, the timestamp need to be in milliseconds

{
 "filterGroups":[
 {
 "filters":[
 {
 "propertyName": "lastmodifieddate",
 "operator": "GT",
 "value": 1646240947414
 }
 ]
 }
 ]
}

@dennisedson

Thank you, the milliseconds did the trick. I had created a PHP multi-dimensional array hoping that json_encode() would convert it into what the API was looking for, but after quite a bit more searching, that doesn’t seem to be the case.