https://api.hubapi.com/crm/v3/objects/contacts/search date filter

Hi,

Im trying to pass a date filter using the new v3 search like so:

“filters”: [
{
“propertyName”: “lastmodifieddate”,
“operator”: “GT”,
“value”: “2020-03-19T23:15:39.161Z”
}

It works when searching for strings, but I get 400 bad request when trying with dates. What format should date be in in the search query for V3 apis? Still unix-time?

{

“status”: “error”,

“message”: “There was a problem with the request.”,

“correlationId”: “8ebe8c45-de7d-4fed-b3e8-4e47cf3f5ee3”

}

I have to imagine it is still Unix time. I’ve been trying the same thing but can’t seem to get the syntax of the call right. I’m using Postman for my R&D. All the parameters from a standard GET v3 Contacts call go into the Body of the call formatted as JSON, right? That is how you get the “filters” in there, right? Got an example?

Trying in postman here too. And yeap, json body, looking like this:

{
“filterGroups”: [
{
“filters”: [
{
“propertyName”: “lastmodifieddate”,
“operator”: “GT”,
“value”: “2020-03-19T23:15:39.161Z”
}
]
}
],
“sorts”: [“”],
“properties”: [
“associatedcompanyid”,
“company”,
“createdate”,
“email”,
“firstname”,
“hs_calculated_phone_number”,
“hs_object_id”,
“hubspot_owner_id”,
“hubspot_team_id”,
“lastmodifieddate”,
“lastname”,
“mobilephone”,
“phone”
],
“limit”: 10,
“after”: 0
}

It works fine to search for lastname for example, but can’t figure out any good time formats that seem to work. Tried Unix time as well but that didn’t do it.

Actually it did work now with Unix time as you said :slightly_smiling_face: , I just forgot to add the milliseconds.

So to answer my own question, yes it is Unixtime, but don’t forget the last milliseconds

Thank You!

Hey @OlaCarlander,

When testing this on my end using Postman, I am able to successfully query my contacts using the following:

{
"filterGroups": [
{
"filters": [
{
"propertyName": "lastmodifieddate",
"operator": "GT",
"value": "1589238000000"
}
]
}
]
}

Note that the value for lastmodifieddate is a UNIX timestamp in milliseconds. This returns the following:

{
 "id": "xxxx",
 "properties": {
 "createdate": "2020-05-12T13:15:22.779Z",
 "hs_is_unworked": "true",
 "lastmodifieddate": "2020-05-12T13:15:22.985Z"
 },
 "createdAt": "2020-05-12T13:15:22.779Z",
 "updatedAt": "2020-05-12T13:15:22.985Z",
 "archived": false
}

I hope this helps!

Hi Matthew, in Postman my URL is

https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey=

my body is

{
“filterGroups”: [
{
“filters”: [
{
“propertyName”: “lastmodifieddate”,
“operator”: “GT”,
“value”: “1589238000000”
}
]
}
],
“properties”: [
“admission_decision”,“application_start_date”,“application_status”,“application_submit_date”,“city,country”,“email”,“firstname”,“gender”,“hs_object_id”,“inquiry_date”,“lastname”,“military_status”,“mobilephone”,“origin_category”,“origin_summary”,“program_of_interest”,“prospect_date”,“slate_events_all”,“slate_most_recent_event”,“slate_most_recent_event_date”,“slate_ref_id”,“source_label”,“stage”,“state”,“when_do_you_plan_to_enroll_”
],
“limit”: 11,
“after”: 1
}

and my response is

<html>

<head>

\<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

\<title>Error 405 Method Not Allowed\</title>

</head>

<body>

\<h2>HTTP ERROR 405\</h2>

\<p>Problem accessing /crm/v3/objects/contacts/search. Reason:

    \<pre>    Method Not Allowed\</pre>

\</p>

</body>

</html>

D’oh! Have to use POST in this scenario…

I’d like to set up a repeatable API call using a Filter on a Date property with a relative value. For example Today(now) - 1 Day. Is there syntax for that or will I have to calculate the relative Unix date value prior to each API call?

https://api.hubapi.com/crm/v3/objects/contacts/search? is the Endpoint

Hey @nadendav

This would be something you’d have to code out on your own server after making the initial API call else, you would indeed need to work with the relative Unix timestamp prior to the call.

Thanks!

the following is not working for me. any advice?

{
 "filterGroups":[
 {
 "filters":[
 {
 "propertyName": "hs_lastmodifieddate",
 "operator": "GT",
 "value": "2021-01-18T15:55:34.185Z"
 }
 ]
 }
 ]
 }

this returns

{
 "status": "error",
 "message": "There was a problem with the request.",
 "correlationId": "5b371826-d7fc-4c0b-b6df-29ad6a861c3d"
}

Hello BStump, the value you provide for a Date Filter must be expressed in Unix Epoch time format. If you read through this entire thread you will see an example.

Why does this request create a new contact?

Hi Vitaly, do you mean why is the POST method needed? Post is required in order to send the message Body with the “filterGroups” and “properties” syntax.

The issue has been resolved. Thank.