hs_lastmodifieddate search via API not work

Hello,

I want to get the latest modified companies of the current day.

My code:

//php get current date:

$date = time() * 1000;

$url = "https://api.hubapi.com/crm/v3/objects/companies/search?hapikey=" . $api\_key;

    // Check if deal is equal to deal stage

    $json\_data = '

    {

        "limit": 100,

        "filters": \[

            "propertyName": "hs\_lastmodifieddate",

            "operator": "GTE",

            "value": "'.$date.'"

            ],

            "properties": \[ "name","exact\_id\_new", "betaalconditie", "g\_l\_account", "land", "state", "zip", "kvk\_nr", "city", "country", "btw", "addres"]

    }

The date is the exact format what HubSpot want, but i still get a error

Hey @TDwebdev,

What error are you getting back from HubSpot? Are you getting a 200 but without results? something similar to the below:

{
 "total": 0,
 "results": []
}

I think the issue here is to do with your filter, you’re getting the current time and looking at any companies that have been modified on or after that timestamp. I think a better route might be to use the BETWEEN operator and look for companies modified in a certain range i.e 24 hours. See below as an example:

POST /crm/v3/objects/companies/search 
Host: api.hubapi.com
Authorization: Bearer {{ access_token }}

{
 "properties": ["domain"],
 "filters": [
 {
 "propertyName": "hs_lastmodifieddate",
 "operator": "BETWEEN",
 "highValue": 1661295600000, // Wed Aug 24 2022 00:00:00
 "value":1661122800000 // Tue Aug 23 2022 00:00:00
 }
 ]
 }

Also, I’d suggest authenticating using an access token (you’d need to create a private app). API keys are being sunset and will no longer work November 30th 2022.