APIs & Integrations

TDwebdev
Contributor | Diamond Partner
Contributor | Diamond Partner

hs_lastmodifieddate search via API not work

SOLVE

Hello,

 

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

 

My code:

//php get current date:

$date = time() * 1000;

        // 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


Vet Digital

Did my post solve your question? Help the community by marking it as a solution
0 Upvotes
1 Accepted solution
coldrickjack
Solution
Top Contributor

hs_lastmodifieddate search via API not work

SOLVE

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.

 

View solution in original post

0 Upvotes
1 Reply 1
coldrickjack
Solution
Top Contributor

hs_lastmodifieddate search via API not work

SOLVE

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.

 

0 Upvotes