# Getting error while searching/filtering contact object with Lastmodifieddate filed.

**URL:** <https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613>\
**Category:** APIs & Integrations\
**Tags:** contacts\
**Created:** [October 12, 2020, 7:52am UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613 "2020-10-12T07:52:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![SakshiChauhan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/sakshichauhan/32/84489_2.png) [@SakshiChauhan](https://community.hubspot.com/u/SakshiChauhan)\
**Post date:** [October 12, 2020, 7:52am UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/1 "2020-10-12T07:52:53Z")

</div>

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=](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,

 ![32948iEBC541014E695AAB.JPG](https://d2qpr2jzcazej7.cloudfront.net/original/3X/4/3/432442bc2bfd4969bd4e48dc5c40e57b29fef23d.jpeg)

and below is the response I’m getting from API

 ![32949iBCF247C9503E1A0B.JPG](https://d2qpr2jzcazej7.cloudfront.net/original/3X/6/8/684f9e6d2e60baa2c39e81565f9c63b44072cea4.jpeg)

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.

 ![32951iE120CE547EB9114E.JPG](https://d2qpr2jzcazej7.cloudfront.net/original/3X/c/9/c94bab95b61b55922392a87f03a56c776d2cce51.jpeg)

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [October 12, 2020, 7:48pm UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/2 "2020-10-12T19:48:31Z")

</div>

hey @SakshiChauhan !

2 things that I am seeing

1. When I ran the test, I needed to us **hs\_lastmodifieddate**. Yours appears to be missing the **hs\_**
2. If you convert the timestamp into its equivalent unix timestamp, I think you should be good to go!

Thanks!

---

<div class="post-metadata">

**Author:** ![SakshiChauhan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/sakshichauhan/32/84489_2.png) [@SakshiChauhan](https://community.hubspot.com/u/SakshiChauhan)\
**Post date:** [October 15, 2020, 8:07am UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/3 "2020-10-15T08:07:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [October 16, 2020, 5:44pm UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/4 "2020-10-16T17:44:55Z")

</div>

hi @SakshiChauhan , you will need to build this into your program.

[Here](https://coderwall.com/p/rbfl6g/how-to-get-the-correct-unix-timestamp-from-any-date-in-javascript) 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!

---

<div class="post-metadata">

**Author:** ![MPrtenjak](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mprtenjak/32/53612_2.png) [@MPrtenjak](https://community.hubspot.com/u/MPrtenjak)\
**Post date:** [October 19, 2020, 8:25am UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/5 "2020-10-19T08:25:39Z")

</div>

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. 😞

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [October 19, 2020, 4:05pm UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/6 "2020-10-19T16:05:07Z")

</div>

Hi @MPrtenjak , could you add the body of your request here?

Thanks!

---

<div class="post-metadata">

**Author:** ![MPrtenjak](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mprtenjak/32/53612_2.png) [@MPrtenjak](https://community.hubspot.com/u/MPrtenjak)\
**Post date:** [October 19, 2020, 5:52pm UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/7 "2020-10-19T17:52:42Z")

</div>

Hi,

I am calling REST function:

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

With body:

```lia-code-sample
{
 "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.

---

<div class="post-metadata">

**Author:** ![MPrtenjak](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mprtenjak/32/53612_2.png) [@MPrtenjak](https://community.hubspot.com/u/MPrtenjak)\
**Post date:** [October 19, 2020, 5:53pm UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/8 "2020-10-19T17:53:19Z")

</div>

Hi,

I am calling REST function:

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

With body:

```lia-code-sample
{
 "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.

---

<div class="post-metadata">

**Author:** ![MPrtenjak](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mprtenjak/32/53612_2.png) [@MPrtenjak](https://community.hubspot.com/u/MPrtenjak)\
**Post date:** [October 19, 2020, 8:39am UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/9 "2020-10-19T08:39:52Z")

</div>

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:

```lia-code-sample
{
 "sorts" : [
 {
 "propertyName": "lastmodifieddate",
 "direction": "DESCENDING"
 } 
 ],
 "limit": 100,
 "after": 400
}

```

---

<div class="post-metadata">

**Author:** ![SakshiChauhan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/sakshichauhan/32/84489_2.png) [@SakshiChauhan](https://community.hubspot.com/u/SakshiChauhan)\
**Post date:** [October 19, 2020, 10:06am UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/10 "2020-10-19T10:06:01Z")

</div>

Hey @dennisedson,  
I checked search API with Unix timestamp with the below payload

```lia-code-sample
{
 "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.

---

<div class="post-metadata">

**Author:** ![PamCotton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pamcotton/32/47916_2.png) [@PamCotton](https://community.hubspot.com/u/PamCotton)\
**Post date:** [October 19, 2020, 2:01pm UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/11 "2020-10-19T14:01:19Z")

</div>

Empty

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [October 19, 2020, 4:58pm UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/12 "2020-10-19T16:58:33Z")

</div>

Hey @SakshiChauhan

Using the post method and this endpoint: [https://api.hubapi.com/crm/v3/objects/companies/search?hapikey=xxxx](https://api.hubapi.com/crm/v3/objects/companies/search?hapikey=xxxx) and using this body (which includes the unix time stamp that you provided):

```lia-code-sample
{
 "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!

---

<div class="post-metadata">

**Author:** ![jtruty](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jtruty/32/35493_2.png) [@jtruty](https://community.hubspot.com/u/jtruty)\
**Post date:** [October 20, 2020, 2:14am UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/13 "2020-10-20T02:14:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MPrtenjak](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mprtenjak/32/53612_2.png) [@MPrtenjak](https://community.hubspot.com/u/MPrtenjak)\
**Post date:** [October 20, 2020, 5:01am UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/14 "2020-10-20T05:01:15Z")

</div>

> * * *
> 
> @jtruty wrote:
> 
> GT/GTE seem to work.
> 
> * * *

Not for me. By using GT/GTE I am getting the same records regardless of ‘value’

---

<div class="post-metadata">

**Author:** ![SakshiChauhan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/sakshichauhan/32/84489_2.png) [@SakshiChauhan](https://community.hubspot.com/u/SakshiChauhan)\
**Post date:** [October 20, 2020, 9:23am UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/15 "2020-10-20T09:23:15Z")

</div>

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.

- In the case of GTE, API returning more than zero records. (expected: should return zero records if I am using the current date.)
- In the case of LTE, API returning zero records. (expected: should return more than zero records if I am using the current date.)

 ![33259i10BC958F0722AA6C.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/4/49ea240adb9bf00eb25f8c06ab0991f19afe2a2c.png)

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

---

<div class="post-metadata">

**Author:** ![jtruty](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jtruty/32/35493_2.png) [@jtruty](https://community.hubspot.com/u/jtruty)\
**Post date:** [October 20, 2020, 2:15pm UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/16 "2020-10-20T14:15:41Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [October 21, 2020, 2:28pm UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/17 "2020-10-21T14:28:59Z")

</div>

Hi @SakshiChauhan , I think I see the problem. Looks like we are submitting in seconds and the endpoint is expecting milliseconds

---

<div class="post-metadata">

**Author:** ![asaeljb](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/asaeljb/32/61905_2.png) [@asaeljb](https://community.hubspot.com/u/asaeljb)\
**Post date:** [October 21, 2020, 7:28pm UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/18 "2020-10-21T19:28:53Z")

</div>

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:

```lia-code-sample
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**.

- **newDate variable is just to verify that the original date does not get affected after the conversion.**

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:

```lia-code-sample
{
 "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

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [October 22, 2020, 3:44pm UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/19 "2020-10-22T15:44:52Z")

</div>

Well done @asaeljb

Thanks for adding your solution here!

---

<div class="post-metadata">

**Author:** ![PMartinez](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pmartinez/32/92090_2.png) [@PMartinez](https://community.hubspot.com/u/PMartinez)\
**Post date:** [September 7, 2021, 5:20pm UTC](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613/20 "2021-09-07T17:20:01Z")

</div>

Thanks, this is very helpful

[Next page](https://community.hubspot.com/t/getting-error-while-searching-filtering-contact-object-with-lastmodifieddate-filed/26613.md?page=2)
