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

Viewed 387

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 = 'https://api.hubapi.com/crm/v3/objects/contacts?limit=100&archived=false&hapikey=xxxxxxxxxxxxxxxxxxx';

// 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
curl_close($ch);

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

{"id":"4764001","properties":{"createdate":"2021-08-04T20:48:28.711Z","hs_is_unworked":"true","hs_marketable_status":"false","hs_marketable_until_renewal":"false","hs_object_id":"4764001","lastmodifieddate":"2021-08-04T20:48:28.711Z"},"createdAt":"2021-08-04T20:48:28.711Z","updatedAt":"2021-08-04T20:48:28.711Z","archived":false}

Thanks in advance guys!

0 Answers
Related