Hubspot CRM API: how to filter on contacts and show desired properties


I am using the Hubspot Contacts API in PHP and I am trying two things:

  1. Filter on a Hubspot Usertoken
  2. Show desired properties of the result

However I don't know how to filter on a usertoken and adding the properties to show, I get the following error: Cannot deserialize instance of java.util.LinkedHashMap out of START_ARRAY token


Here is the necessary code:

$url = '';

// Create a new cURL resource
$ch = curl_init($url);

// Setup request to send json via POST
$data = array(
    'properties' => array(
        'firstname', 'lastname', 'email'
    'filters' => array(
            'propertyName' => 'firstname',
            'operator'=> 'EQ',
            'value'=> 'Mats'
$payload = json_encode($data);

echo $payload;

// Attach encoded JSON string to the POST fields
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

// Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

// Return response instead of outputting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute the POST request
$result = curl_exec($ch);

// Close cURL resource


When I remove the 'properties' from the data, I get the following result (which seems empty, but I know for a fact that there is someone with first name Mats in the database, being me):



Thanks in advance guys!

2 Replies 2
Top Contributor | Diamond Partner

Hi @MRaemen ,

Please try below code for found result:

$data = '{
"propertyName": "firstname",
"operator": "EQ",
"value": "<VALUE>"
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards. 


Dear @webdew thank you for your reply.


This works indeed, thank you very much.

However I can still not search on the usertoken that's stored in the cookie. 


Is this possible? I want to be able to get the first and last name of the person on our website if they have ever entered it in Hubspot in the past.


In theory this should seem possible as the 'hubspotutk' cookie is probably stored in the Hubspot database when I send in form data. In practice however, I can't seem to get it to work.