# Problem with API contacts search using php client library

**URL:** <https://community.hubspot.com/t/problem-with-api-contacts-search-using-php-client-library/51434>\
**Category:** APIs & Integrations\
**Tags:** php, sdk, contacts\
**Created:** [February 12, 2022, 3:34pm UTC](https://community.hubspot.com/t/problem-with-api-contacts-search-using-php-client-library/51434 "2022-02-12T15:34:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![JNichel](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@JNichel](https://community.hubspot.com/u/JNichel)\
**Post date:** [February 12, 2022, 3:34pm UTC](https://community.hubspot.com/t/problem-with-api-contacts-search-using-php-client-library/51434/1 "2022-02-12T15:34:27Z")

</div>

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](https://developers.hubspot.com/docs/api/crm/contacts)) 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.

---

<div class="post-metadata">

**Author:** ![Ismail](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ismail/32/33878_2.png) [@Ismail](https://community.hubspot.com/u/Ismail)\
**Post date:** [February 12, 2022, 3:40pm UTC](https://community.hubspot.com/t/problem-with-api-contacts-search-using-php-client-library/51434/2 "2022-02-12T15:40:48Z")

</div>

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

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

I hope this is helpful.

---

<div class="post-metadata">

**Author:** ![JNichel](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@JNichel](https://community.hubspot.com/u/JNichel)\
**Post date:** [February 12, 2022, 3:59pm UTC](https://community.hubspot.com/t/problem-with-api-contacts-search-using-php-client-library/51434/3 "2022-02-12T15:59:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ismail](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ismail/32/33878_2.png) [@Ismail](https://community.hubspot.com/u/Ismail)\
**Post date:** [February 12, 2022, 5:13pm UTC](https://community.hubspot.com/t/problem-with-api-contacts-search-using-php-client-library/51434/4 "2022-02-12T17:13:53Z")

</div>

@JNichel I think the property name is “hs\_lastmodifieddate”  
This works on postman  
POST: [https://api.hubapi.com/crm/v3/objects/deals/search?hapikey=\](https://api.hubapi.com/crm/v3/objects/deals/search?hapikey=%5C)

{

“filterGroups”: [

{

“filters”: [

{

“value”: “1643598000000”,

“propertyName”: “hs\_lastmodifieddate”,

“operator”: “GT”

}

]

}

]

}

---

<div class="post-metadata">

**Author:** ![JNichel](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@JNichel](https://community.hubspot.com/u/JNichel)\
**Post date:** [February 14, 2022, 7:18pm UTC](https://community.hubspot.com/t/problem-with-api-contacts-search-using-php-client-library/51434/5 "2022-02-14T19:18:16Z")

</div>

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

> **[Search the CRM - HubSpot docs](https://developers.hubspot.com/docs/api-reference/latest/crm/search-the-crm)**
>
> The CRM search endpoints make getting data more efficient by allowing developers to filter, sort, and search across any CRM object type.

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](https://developers.hubspot.com/docs/api/overview)) 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](https://developers.hubspot.com/docs/api/crm/contacts) 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.

---

<div class="post-metadata">

**Author:** ![tominal](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tominal/32/73018_2.png) [@tominal](https://community.hubspot.com/u/tominal)\
**Post date:** [February 16, 2022, 3:08am UTC](https://community.hubspot.com/t/problem-with-api-contacts-search-using-php-client-library/51434/6 "2022-02-16T03:08:14Z")

</div>

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 “=\>”.

 ![RBThomas_0-1644980729272.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/e/c/ec6760b80a6f570bbf1f177e0ad4c6b9b9d63e49.png)

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!

---

<div class="post-metadata">

**Author:** ![JNichel](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@JNichel](https://community.hubspot.com/u/JNichel)\
**Post date:** [February 16, 2022, 12:52pm UTC](https://community.hubspot.com/t/problem-with-api-contacts-search-using-php-client-library/51434/7 "2022-02-16T12:52:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tominal](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tominal/32/73018_2.png) [@tominal](https://community.hubspot.com/u/tominal)\
**Post date:** [February 16, 2022, 3:49pm UTC](https://community.hubspot.com/t/problem-with-api-contacts-search-using-php-client-library/51434/8 "2022-02-16T15:49:22Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![tominal](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tominal/32/73018_2.png) [@tominal](https://community.hubspot.com/u/tominal)\
**Post date:** [February 16, 2022, 3:10am UTC](https://community.hubspot.com/t/problem-with-api-contacts-search-using-php-client-library/51434/9 "2022-02-16T03:10:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JNichel](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@JNichel](https://community.hubspot.com/u/JNichel)\
**Post date:** [February 16, 2022, 12:43pm UTC](https://community.hubspot.com/t/problem-with-api-contacts-search-using-php-client-library/51434/10 "2022-02-16T12:43:27Z")

</div>

Thank you for this.
