Filtering by hs_lastmodifieddate in Search API

Hi,

I am trying to user the search API filtering by hs_lastmodifieddate, but it seems that API is not filtering the result.

The code:

public_object_search_request = PublicObjectSearchRequest( limit=100, filter_groups=[ { "propertyName": "hs_lastmodifieddate", "operator": "BETWEEN", "highValue": 1670454000000, "value":1670461200000 }], sorts=[{"propertyName": "hs_object_id", "direction": "ASCENDING"}], properties=properties)response = api_client.crm.deals.search_api.do_search( public_object_search_request=public_object_search_request,)

The time is in miliseconds, but I don’t know where is the problem because I am receiving more results than expected.

Any ideas?

Thanks in advance.

Hey @adrivid ,

thank you for reaching out. I wouldn’t call myself an expert, but I have two ideas of what might cause problems.

The first is that it appears that the two values (highValue and value) need to be switched around. The other one is, that the timestamps need to be in a string format according to the docs. I’m not really sure about that one as I looked at my code, and it’s also in integers, but who knows… might do the trick after all.

Maybe this helps. Please let us know how it goes.

Cheers,

Chriso

Hi,

I have tried with a strings and the result is not filtered.

I don’t know where is the error.

Do you have some working code?

Thank you so much.

Hey @adrivid ,

the issue was that you were missing the filters list element within the filterGroups argument. So, in total, your code should look something like this:

import os
from pprint import pprint
from hubspot import HubSpot
from hubspot.crm.deals import PublicObjectSearchRequest, ApiException

api_client = HubSpot(access_token=os.getenv("access_token"))

properties = ["name"] # Don't forget your properties

public_object_search_request = PublicObjectSearchRequest(
 filter_groups=[
 {
 "filters": [
 {
 "propertyName": "hs_lastmodifieddate",
 "operator": "BETWEEN",
 "highValue": 1670461200000,
 "value": 1670454000000,
 }
 ]
 }
 ],
 sorts=[{"propertyName": "hs_object_id", "direction": "ASCENDING"}],
 properties=properties,
)
try:
 api_response = api_client.crm.deals.search_api.do_search(
 public_object_search_request=public_object_search_request
 )
 pprint(api_response)
except ApiException as e:
 print("Exception when calling search_api->do_search: %s\n" % e)

If you found this post helpful, consider helping others in the community to find answers faster by marking this as a solution. I’d really appreciate it.

Cheers,

Chriso

Hi @ChrisoKlepke ,

Thanks for your answer. I did a lot of tests and you are right, the one that I have posted constains an error. The values have to be switched.

This aside, I tried with the GT operator (for example) with the same result. The response is not filtered.

I am going to check it again trying to use string values instead of ints.

Thank you for your answer again.

I will keep you informed.

I seem to have a similar problem. I’m using this piece of code to get a certain list of Deals:

 const dealFilter = { propertyName: "createdate", operator: "BETWEEN", 
highValue: 1609369200000, value: 1577833200000 }
 const dealFilterGroup = { filters: [dealFilter] }
 const dealSearchRequest = { filterGroups: [dealFilterGroup] }
 hubspotClient.crm.deals.searchApi.doSearch(dealSearchRequest)
 .then(dealResult => {
 if (dealResult.body.total > 0) {
 console.log (dealResult.body.total);
 }
 })

But I keep getting this error:

"status":"error","message":"Invalid input JSON on line 1, column 101: operator BETWEEN requires a highValue"

Obviously, the highValue is available, so what am I doing wrong?