1 year ago

#239847

test-img

John

Invalid input JSON when using HubSpot API 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.HashSet` from Object value (token `JsonToken.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 HubSpot's community with similar errors, but no solutions that worked for me.

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));

I also posted this on HubSpot's community forums, but I've always had better luck here. Any help with what I'm doing wrong would be greatly appreciated.

output from echo print_r($response);

stdClass Object ( 
    [status] => error 
    [message] => Invalid input JSON on line 1, column 17: Cannot deserialize value of type java.util.HashSet from Object value (token JsonToken.START_OBJECT) 
    [correlationId] => 6737df28-b53c-4add-81ae-cd19b722e01c 
)

php

json

curl

hubspot-api

0 Answers

Your Answer

Accepted video resources