Problem with API contacts search using php client library

Hi, I’m afraid this is going to be a n00b question but I can figure out what I’m doing wrong. I would like to pull a list of contacts that have been modified after $date. Seems easy enough, right? Going thru the docs I find the search endpoint in the crm section of the v3 API (Accounts Dashboard | HubSpot) and copy the code into my IDE. I make some modifications to hopefully only return contacts modified after 31 January and try running the script. Unfortunately, there seems to be a syntax error in the code from docs page (I get an error when running it from there as well) and my “skills” are lacking when it comes to finding it. My code is:

use HubSpot\Factory;
use HubSpot\Client\Crm\Contacts\ApiException;

$client = Factory::createWithApiKey(“68153de2-75f0-4aa0-b35b-28bc1a4dd82f”);

$PublicObjectSearchRequest = new PublicObjectSearchRequest([‘filter_groups’ => [{“filters”:[{“value”:“2022-01-31”,“propertyName”:“lastmodifieddate”,“operator”:“GT”}]}], ‘sorts’ => [“DESCENDING”], ‘properties’ => [“ALL”], ‘limit’ => 20, ‘after’ => 0]);
try {
$apiResponse = $client->crm()->contacts()->searchApi()->doSearch($PublicObjectSearchRequest);
var_dump($apiResponse);
} catch (ApiException $e) {
echo "Exception when calling search_api->do_search: ", $e->getMessage();
}

My IDE and server logs are telling me that the error is the curly brace before “filters”, ie

PublicObjectSearchRequest([‘filter_groups’ => [

{

“filters”:[{“value”

I’ve tried working with the braces and brackets, but this syntax is foreign to me and I cannot find the right combination. Any help/point in the right direction is greatly appreciated.

Hi @JNichel Hubspot uses Unix timestamp in milliseconds for date value

So instead if “2022-01-31” use 1643598000000

I hope this is helpful.

Hi Ismail, that is helpful going forward, but it didn’t solve the syntax issue, “syntax error, unexpected ‘{’, expecting ‘]’”, right before filters.

@JNichel I think the property name is “hs_lastmodifieddate”
This works on postman
POST: https://api.hubapi.com/crm/v3/objects/deals/search?hapikey=\

{

“filterGroups”: [

{

“filters”: [

{

“value”: “1643598000000”,

“propertyName”: “hs_lastmodifieddate”,

“operator”: “GT”

}

]

}

]

}

Ismail, I appreciate your response, but according to the docs here:

The property I’m looking to search on for contacts is lastmodifieddate. The example you’re showing is for deals. I understand that it may work in different areas and/or languages, but I’m trying to use the HubSpot provided PHP SDK (2026-03 API reference - HubSpot docs) so that I can spend more time working with the data instead of writing my own tools.

I copied the example from the search endpoint here Accounts Dashboard | HubSpot but that is what is throwing the syntax error. It throws an error when you try to test the example on their own site. The other parts of the PHP SDK that I’ve used work fine, so I just wrote something using cURL for the search endpoint until a fix is in place.

Hey @JNichel,

I would spend some time practicing with PHP arrays. This error is telling you you’re trying to mix objects with multidimensional arrays. You are also not allowed to use colons as assignment operators in PHP.

In short, replace all of those {} with [] and colons with “=>”.

P.S. I have found that the PHP SDK is not intuitive. Instead, I wrote my own cURL wrapped functions to handle data with HubSpot.

I hope that helps!

It did help. Thank you. I haven’t seriously written any code in a lot of years and even though the example didn’t look right to me, I thought it had to be correct because it was in the SDK documentation. Like maybe it was shorthand for creating arrays.

That’s awesome to hear! Also, I am so used to defining arrays that way I did not even think to mention that it is a shorthand for creating arrays as well.

$var = [];

is the same as

$var = array();

I hope you have more luck than I did with the SDK!

Also, I just noticed this. You are going to need to re-roll your API key since you leaked it in your original post.

Thank you for this.