We use cookies to make HubSpot's community a better place. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. To learn more, and to see a full list of cookies we use, check out our Cookie Policy (baked goods not included).
Oct 12, 2020 3:52 AM
I'm using Filter, sort, and search CRM Objects API to filter contacts based on the Lastmodifieddate field and getting an error in response from API ( URL: "https://api.hubapi.com/crm/v3/objects/companies/search?hapikey=" )
In the contacts record, there is more than one record which has Lastmodifieddate. Tried with different filters like the first-name and it's working fine with first-name and other filters.
below is the request body I'm passing,
and below is the response I'm getting from API
It should give me records matching with Lastmodifieddate but it's giving me an error.
The same request is working with filters like first-name, hs_object_id.
Please point me to the right path, is there anything that I'm missing? Or filtering with Lastmodifieddate and updatedAt is not supported?
please refer to below Snapshot which supports me that I've records ( contact records ) that have the Lastmodifieddate field with its value.
Solved! Go to Solution.
Oct 21, 2020 3:28 PM
Hi everyone,
I have been working with the HubSpot API as well and these are my findings:
To convert a date to an epoch unix timestamp you can use this simple JavaScript code:
var originalDate = '2020-10-13T15:47:31.233Z'; //original date obtained from any record
var epochDate = Date.parse(originalDate);
var newDate = new Date(epochDate);
console.log(epochDate);
console.log(newDate.toUTCString());
You can use the value of the epochDate variable to retrieve the records you want from HubSpot API, the format of the epoch timestamp should be something like this 1602604051233.
I have been using the Search API method for Contacts by calling the following URL:
https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey=xxxx
And using this body:
{
"sorts": [
{
"propertyName": "lastmodifieddate",
"direction": "ASCENDING"
}
],
"filterGroups":[
{
"filters": [
{
"propertyName": "lastmodifieddate",
"operator": "GTE",
"value": "1602604051233"
}
]
}
]
}
As shown above, GTE is being used as the operator for that request, but I also tested with LT,LTE, and GT and these operators work fine as well.
Hope it helps, best regards!
Thanks,
Asael
Oct 23, 2020 10:12 AM
Thanks @asaeljb @dennisedson, for providing the solution. I am marking this post as resolved.
Oct 21, 2020 3:28 PM
Hi everyone,
I have been working with the HubSpot API as well and these are my findings:
To convert a date to an epoch unix timestamp you can use this simple JavaScript code:
var originalDate = '2020-10-13T15:47:31.233Z'; //original date obtained from any record
var epochDate = Date.parse(originalDate);
var newDate = new Date(epochDate);
console.log(epochDate);
console.log(newDate.toUTCString());
You can use the value of the epochDate variable to retrieve the records you want from HubSpot API, the format of the epoch timestamp should be something like this 1602604051233.
I have been using the Search API method for Contacts by calling the following URL:
https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey=xxxx
And using this body:
{
"sorts": [
{
"propertyName": "lastmodifieddate",
"direction": "ASCENDING"
}
],
"filterGroups":[
{
"filters": [
{
"propertyName": "lastmodifieddate",
"operator": "GTE",
"value": "1602604051233"
}
]
}
]
}
As shown above, GTE is being used as the operator for that request, but I also tested with LT,LTE, and GT and these operators work fine as well.
Hope it helps, best regards!
Thanks,
Asael
Sep 7, 2021 1:20 PM
Thanks, this is very helpful
Oct 22, 2020 11:44 AM
Well done @asaeljb
Thanks for adding your solution here!
![]() | Make sure to subscribe to our YouTube channel where you can find the HubSpot Community Developer Show |
Oct 21, 2020 10:28 AM
Hi @SakshiChauhan , I think I see the problem. Looks like we are submitting in seconds and the endpoint is expecting milliseconds
![]() | Make sure to subscribe to our YouTube channel where you can find the HubSpot Community Developer Show |
Oct 20, 2020 5:23 AM
Hi @dennisedson,
1. I checked your created request on postman and getting the same 8 records for companies object but according to me, it is not correct.
2. In case of Contact hs_lastmodifieddate not working. Search API is returning zero records or if I use lastmodifieddate without hs_ in Contacts object then it gives me data.
So please suggest
Oct 20, 2020 10:15 AM
@SakshiChauhan @dennisedson I can confirm I see the same issue - it appears that the GT/GTE/LT/LTE don't work properly using Unix dates as shown in the example. Should we be using a different format?
Oct 19, 2020 10:14 PM
I am seeing something similar - it appears LTE date math doesn't work properly on datetime fields using the unix timestamp as shown above. 0 records are always returned for me as well. GT/GTE seem to work.
Oct 20, 2020 1:01 AM
@jtruty wrote:GT/GTE seem to work.
Not for me. By using GT/GTE I am getting the same records regardless of 'value'
Oct 19, 2020 12:58 PM
Hey @SakshiChauhan
Using the post method and this endpoint: https://api.hubapi.com/crm/v3/objects/companies/search?hapikey=xxxx and using this body (which includes the unix time stamp that you provided):
{
"filterGroups":[
{
"filters": [
{
"propertyName": "hs_lastmodifieddate",
"operator": "GTE",
"value": "1603101460"
}
]
}
]
}
I received 8 entries in my returned body.
Hopefully, this updated code will help you out!
![]() | Make sure to subscribe to our YouTube channel where you can find the HubSpot Community Developer Show |
Oct 19, 2020 10:01 AM
Oct 19, 2020 6:06 AM
Hey @dennisedson,
I checked search API with Unix timestamp with the below payload
{
"filterGroups": [
{
"filters": [
{
"propertyName": "hs_lastmodifieddate",
"operator": "LTE",
"value": "1603101460"
}
]
}
]
}
It always returns zero results with 200 status code, but we have more than zero records according to the provided filter.
Oct 19, 2020 4:39 AM
Ok, I have found a workaround. Sort contacts by modified date read chunks of 100 records (max allowed) until some arbitrary time I am looking for:
{
"sorts" : [
{
"propertyName": "lastmodifieddate",
"direction": "DESCENDING"
}
],
"limit": 100,
"after": 400
}
Oct 15, 2020 4:07 AM
Hey, @dennisedson thanks for the update.
but can you please help me with how can I convert modified_date into Unix timestamp?
Below is my modified date of one record that I wanted to search by HubSpot API.
"2020-09-11T19:42:24.233Z"
Oct 16, 2020 1:44 PM
hi @SakshiChauhan , you will need to build this into your program.
Here is an article that may help.
For what it's worth, I have brought this up to the team to consider updating so the methods return a consistent value. Hopefully this will be updated sooner than later!
![]() | Make sure to subscribe to our YouTube channel where you can find the HubSpot Community Developer Show |
Oct 19, 2020 4:25 AM
HI,
It does not work. Even if I translate string to UnixTime.
If I use lastmodifieddate and "GTE". I get all records regardless of timestamp.
If I use lastmodifieddate and "LTE" I get no records regardless of timestamp.
If I use hs_lastmodifieddate I get no restords regardless of timestamp, operator....
And also value can be as string or as number - it doesn't matter
All I need is api call which will return records that were modified after some arbitrary time. With that I can synchronize local contacts with HubSpot. Just periodically execute function which will return all records that were changed after last call. 😞
Oct 19, 2020 12:05 PM
Hi @MPrtenjak , could you add the body of your request here?
Thanks!
![]() | Make sure to subscribe to our YouTube channel where you can find the HubSpot Community Developer Show |
Oct 19, 2020 1:53 PM
Hi,
I am calling REST function:
https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey=xxxx
With body:
{
"filters": [
{
"propertyName": "lastmodifieddate",
"operator": "GTE",
"value": 1601544240
}
]
}
Now you can change value to anything and you will always records. I can set value to 0 or 1601544240 or 2601544240 - it doesn't matter. I will always get all records
If I change GTE to LTE I won't get any records.
Oct 19, 2020 1:52 PM
Hi,
I am calling REST function:
https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey=xxxx
With body:
{
"filters": [
{
"propertyName": "lastmodifieddate",
"operator": "GTE",
"value": 1601544240
}
]
}
Now you can change value to anything and you will always records. I can set value to 0 or 1601544240 or 2601544240 - it doesn't matter. I will always get all records
If I change GTE to LTE I won't get any records.
Oct 12, 2020 3:48 PM - edited Oct 12, 2020 3:48 PM
hey @SakshiChauhan !
2 things that I am seeing
Thanks!
![]() | Make sure to subscribe to our YouTube channel where you can find the HubSpot Community Developer Show |