APIs & Integrations

PMunar
Participant | Elite Partner
Participant | Elite Partner

Problem trying to filter by a custom property

SOLVE

Hi everyone.

 

I am trying to filter contact information based on a custom property, which has a Date format (in the UI I see it as a date picker format).

Its name is "fecha_inicio_suscripcion".

 

I am running it through the API endpoint: https://api.hubapi.com/crm/v3/objects/contacts/search

 

The filters I apply are:

 

{
"filterGroups": [
{
"filters": [{
"propertyName": "fecha_inicio_suscripcion",
"operator": "HAS_PROPERTY"
},
{
"propertyName": "fecha_inicio_suscripcion",
"operator": "EQ",
"value": '2020-12-2'
}
]
}
],
"properties": ["associated_deal_id", "fecha_inicio_suscripcion"],
"limit": 10,
}

 

When I run my query with this parameters, I get this error:

 

Error fetching contacts: 400 Client Error: Bad Request for url: https://api.hubapi.com/crm/v3/objects/contacts/search

 which is quite generic.

 

If I comment the part of the "EQ" filter, I do get a response and a contact list. In this contact list, I see the field "fecha_inicio_suscripcion". An example of what I get is this:

 

{'total': 1,
 'results': [{'id': '28755',
   'properties': {'createdate': '2021-05-25T12:34:47.784Z',
    'fecha_inicio_suscripcion': '2020-12-02',
    'hs_object_id': '28755',
    'lastmodifieddate': '2025-03-25T20:49:21.333Z'},
   'createdAt': '2021-05-25T12:34:47.784Z',
   'updatedAt': '2025-03-25T20:49:21.333Z',
   'archived': False}]}

 

I do not understand why I cannot filter by the "fecha_inicio_suscripcion" field if it is present in the records I get and the format is normal YYYY-MM-DD date format.

 

Any help would mean a lot! Thanks!

0 Upvotes
1 Accepted solution
MichaelMa
Solution
Contributor

Problem trying to filter by a custom property

SOLVE

Date picker type uses Unix Timestamp. For Dec 02 2020 (time set to 00:00:00 GMT+0000), you would use 1606867200 (seconds) or 1606867200000 (milliseconds). You would need to convert your date to a Unix Timestamp for the API to work.

 

Did you want an OR condition in your filter?

 

In an AND operator, the second part of your filter (looking for a specific value) makes the first part of the filter unneeded. If you are searching for ONLY records with X value, there's no need to check if there is a value in there. null records will not be returned if you are searching for a specific value.

 

If you want an OR operator, aka any record that has a value, the first filter makes the second filter redundant.

 

From a programming perspective, you do not need to check if a field exists/field has value before checking it's value. That said, there's no reason you can't have the filters like you have it now but I'm just mentioning that it's a redundant filter to the task at hand.

 

View solution in original post

0 Upvotes
4 Replies 4
MichaelMa
Contributor

Problem trying to filter by a custom property

SOLVE

Let's deal with the error first. 

 

Is fecha_inicio_suscripcion a date field? Using the API, it expects a Unix Timestamp as the data. So you need to convert your date to Unix Timestamp and use that. GraphQL does support using an ISO formatted date as a filter.

 

Are you trying to do an OR statement between the two filters or an AND statement? Your current filters are using and AND operator. The first filter (has property) is made redundant because you're search for contacts specifically with a value of "2020-12-2".

 

0 Upvotes
PMunar
Participant | Elite Partner
Participant | Elite Partner

Problem trying to filter by a custom property

SOLVE

Hi! 

In the Hubspot UI, going to the settings and there looking for the contatc property "fecha_inicio_suscripcion" I see that the format is Date picker (look at the screenshot). So I guess that the format the API retrieves is that.

 

The fact that I put the "HAS_PROPERTY" condition is because there are records where "fecha_inicio_suscripcion" is None, so I wanted to obtain only those records where it had some value. 

 

Captura de pantalla 2025-03-26 a las 16.45.15.png

 

Is there a way to assess the format of the "fecha_inicio_suscripcion" property as it is returned by the API?

 

Thanks!

0 Upvotes
MichaelMa
Solution
Contributor

Problem trying to filter by a custom property

SOLVE

Date picker type uses Unix Timestamp. For Dec 02 2020 (time set to 00:00:00 GMT+0000), you would use 1606867200 (seconds) or 1606867200000 (milliseconds). You would need to convert your date to a Unix Timestamp for the API to work.

 

Did you want an OR condition in your filter?

 

In an AND operator, the second part of your filter (looking for a specific value) makes the first part of the filter unneeded. If you are searching for ONLY records with X value, there's no need to check if there is a value in there. null records will not be returned if you are searching for a specific value.

 

If you want an OR operator, aka any record that has a value, the first filter makes the second filter redundant.

 

From a programming perspective, you do not need to check if a field exists/field has value before checking it's value. That said, there's no reason you can't have the filters like you have it now but I'm just mentioning that it's a redundant filter to the task at hand.

 

0 Upvotes
PMunar
Participant | Elite Partner
Participant | Elite Partner

Problem trying to filter by a custom property

SOLVE

Hi again.

With the Unix Timestamp it worked. Thanks a lot for the information.

As for the OR or AND filters, I get it. Since I want the AND, I will remove it from the query, just as you said.

 

Thanks a lot again!

0 Upvotes