APIs & Integrations

OlaCarlander
Participant

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

SOLVE

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"
}
0 Upvotes
1 Accepted solution
Willson
Solution
HubSpot Employee
HubSpot Employee

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

SOLVE

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!

Product Manager @ HubSpot

View solution in original post

14 Replies 14
Vitaly_Gubkin
Member

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

SOLVE

Why does this request create a new contact?

0 Upvotes
nadendav
Member

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

SOLVE

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. 

0 Upvotes
Vitaly_Gubkin
Member

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

SOLVE

The issue has been resolved. Thank.

0 Upvotes
nadendav
Member

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

SOLVE

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?  

0 Upvotes
OlaCarlander
Participant

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

SOLVE

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. 

0 Upvotes
Willson
Solution
HubSpot Employee
HubSpot Employee

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

SOLVE

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!

Product Manager @ HubSpot
BStump
Member

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

SOLVE

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"
}

 

0 Upvotes
nadendav
Member

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

SOLVE

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.

nadendav
Member

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

SOLVE

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>
0 Upvotes
nadendav
Member

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

SOLVE

D'oh! Have to use POST in this scenario...

0 Upvotes
nadendav
Member

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

SOLVE

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

0 Upvotes
Willson
HubSpot Employee
HubSpot Employee

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

SOLVE

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!

Product Manager @ HubSpot
0 Upvotes
OlaCarlander
Participant

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

SOLVE

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

 

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

nadendav
Member

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

SOLVE

Thank You!

0 Upvotes