APIs & Integrations

CSwart
Participant

[Hubspot API] How do you use IN filter operator?

SOLVE

I am trying to use an IN Filter for getting all deals from a list of deal_ids when trying this I get an invalid JSON error:

 

HTTP response body: {
"status":"error",
"message":"Invalid input JSON on line 1, column 42: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token",
"correlationId":"dd4d7def-6cc8-4b7e-a48d-658e0330e8cd"
}

 


I am using the Python API as such to do the IN filter operation with a list of deal_id strings in deal_ids:

 

domain_filter = hubspot.crm.deals.models.Filter(
            property_name="id",
            operator="IN",
            value=deal_ids
        )

        filter_group = hubspot.crm.deals.models.FilterGroup(
            filters=[domain_filter]
        )

        public_object_search_request = hubspot.crm.companies.models.PublicObjectSearchRequest(
            filter_groups=[filter_group]
        )
        
        deal_results = self.hubspot_api_client.crm.companies.search_api.do_search(public_object_search_request=public_object_search_request)

 

 

This is what the dict repr of public_object_search_request looks like:

 

{'after': None,
 'filter_groups': [{'filters': [{'operator': 'IN',
                                 'property_name': 'id',
                                 'value': ['3651752129', '3741754830']}]}],
 'limit': None,
 'properties': None,
 'query': None,
 'sorts': None}

Would love to see a working IN operator example to get it working for myself.

0 Upvotes
1 Accepted solution
Teun
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

[Hubspot API] How do you use IN filter operator?

SOLVE

Hi @CSwart ,

 

I checked the Deals docs, and I think you can retrieve the deals with two endpoints.

 

Batch read (inputs= should get your array of ID's):

import hubspot
from pprint import pprint
from hubspot.crm.deals import BatchReadInputSimplePublicObjectId, ApiException

client = hubspot.Client.create(api_key="YOUR_HUBSPOT_API_KEY")

batch_read_input_simple_public_object_id = BatchReadInputSimplePublicObjectId(properties="dealname", inputs=[{"id":"3651752129"},{"id":"3741754830"}])
try:
    api_response = client.crm.deals.batch_api.read(archived=False, batch_read_input_simple_public_object_id=batch_read_input_simple_public_object_id)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling batch_api->read: %s\n" % e)

 

Search:

import hubspot
from pprint import pprint
from hubspot.crm.deals import PublicObjectSearchRequest, ApiException

client = hubspot.Client.create(api_key="YOUR_HUBSPOT_API_KEY")

public_object_search_request = PublicObjectSearchRequest(filter_groups={"filters":[{"value":"3741754830","propertyName":"hs_object_id","operator":"EQ"},{"value":"3651752129","propertyName":"hs_object_id","operator":"EQ"}]}, sorts="dealname", query="string", properties="dealname", limit=10, after=0)
try:
    api_response = client.crm.deals.search_api.do_search(public_object_search_request=public_object_search_request)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling search_api->do_search: %s\n" % e)

OR:

import hubspot
from pprint import pprint
from hubspot.crm.deals import PublicObjectSearchRequest, ApiException

client = hubspot.Client.create(api_key="YOUR_HUBSPOT_API_KEY")

public_object_search_request = PublicObjectSearchRequest(filter_groups={"filters":[{"value":"[\"3651752129\", \"3741754830\"]","propertyName":"hs_object_id","operator":"IN"}]}, sorts="dealname", query="string", properties="dealname", limit=10, after=0)
try:
    api_response = client.crm.deals.search_api.do_search(public_object_search_request=public_object_search_request)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling search_api->do_search: %s\n" % e)

 



Did my answer solve your issue? Help the community by marking it as the solution.

View solution in original post

11 Replies 11
SNowak6
Member

[Hubspot API] How do you use IN filter operator?

SOLVE

Hi! I have a problem when trying to search products using custom property. When I use "EQ" operator I'm getting a product as a result:

{
  "filterGroups": [
    {
      "filters": [
        {
          "value""VKBA 1355",
          "propertyName""litium_productarticlenumber",
          "operator""EQ"
        }
      ]
    }
  ],
  "properties": [
    "litium_productarticlenumber"
  ]
}

But when I try to do same search (and search with more values) using "IN" operator I'm not getting anything:

{
  "filterGroups": [
    {
      "filters": [
        {
          "values""VKBA 1355""VKBA 3434" ],
          "propertyName""litium_productarticlenumber",
          "operator""IN"
        }
      ]
    }
  ],
  "properties": [
    "litium_productarticlenumber"
  ]
}
 
What am I doing wrong?

 

 

0 Upvotes
BSeslija
Member

[Hubspot API] How do you use IN filter operator?

SOLVE

Hi! I am trying to filter contact data based on date created. I have added this to request body: 

{
"filters": [
{"propertyName": "createdate",
"operator": "IN",
"values": ["2022-03-01", "2022-03-31"]
}]
}

But I always get  There was a problem with the request as a response. 

What am I doing wrong?

0 Upvotes
BSeslija
Member

[Hubspot API] How do you use IN filter operator?

SOLVE

Hi!  I am trying to filter search results and get contacts data based on date created. I added this to request body: 

{
"filters": [
{
"propertyName": "createdate",
"operator": "IN",
"values": ["2022-03-01T00:00:29.962Z", "2022-03-31T00:00:29.962Z"]
}
]
}

But I always get There was a problem with the request in the response. 

What am I doing wrong?

0 Upvotes
Petercopter
Participant

[Hubspot API] How do you use IN filter operator?

SOLVE

Thanks for puzzling this out. Here's an example that works in Ruby. Note the VALUES key

{
  filterGroups: [
    {
      filters: [
        {
          operator: 'IN',
          propertyName: 'dealstage',
          values: ['closedlost', 'closedwon']
        }
      ]
    }
  ],
  sorts: [{ direction: 'ASCENDING', propertyName: 'dealname' }]
}

 

0 Upvotes
mooney
Participant

[Hubspot API] How do you use IN filter operator?

SOLVE

are you able to filter using any other values other than closedlost and closedwon such as custom stages?

0 Upvotes
Teun
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

[Hubspot API] How do you use IN filter operator?

SOLVE

Hi @CSwart ,

 

I checked the Deals docs, and I think you can retrieve the deals with two endpoints.

 

Batch read (inputs= should get your array of ID's):

import hubspot
from pprint import pprint
from hubspot.crm.deals import BatchReadInputSimplePublicObjectId, ApiException

client = hubspot.Client.create(api_key="YOUR_HUBSPOT_API_KEY")

batch_read_input_simple_public_object_id = BatchReadInputSimplePublicObjectId(properties="dealname", inputs=[{"id":"3651752129"},{"id":"3741754830"}])
try:
    api_response = client.crm.deals.batch_api.read(archived=False, batch_read_input_simple_public_object_id=batch_read_input_simple_public_object_id)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling batch_api->read: %s\n" % e)

 

Search:

import hubspot
from pprint import pprint
from hubspot.crm.deals import PublicObjectSearchRequest, ApiException

client = hubspot.Client.create(api_key="YOUR_HUBSPOT_API_KEY")

public_object_search_request = PublicObjectSearchRequest(filter_groups={"filters":[{"value":"3741754830","propertyName":"hs_object_id","operator":"EQ"},{"value":"3651752129","propertyName":"hs_object_id","operator":"EQ"}]}, sorts="dealname", query="string", properties="dealname", limit=10, after=0)
try:
    api_response = client.crm.deals.search_api.do_search(public_object_search_request=public_object_search_request)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling search_api->do_search: %s\n" % e)

OR:

import hubspot
from pprint import pprint
from hubspot.crm.deals import PublicObjectSearchRequest, ApiException

client = hubspot.Client.create(api_key="YOUR_HUBSPOT_API_KEY")

public_object_search_request = PublicObjectSearchRequest(filter_groups={"filters":[{"value":"[\"3651752129\", \"3741754830\"]","propertyName":"hs_object_id","operator":"IN"}]}, sorts="dealname", query="string", properties="dealname", limit=10, after=0)
try:
    api_response = client.crm.deals.search_api.do_search(public_object_search_request=public_object_search_request)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling search_api->do_search: %s\n" % e)

 



Did my answer solve your issue? Help the community by marking it as the solution.
mooney
Participant

[Hubspot API] How do you use IN filter operator?

SOLVE

HI @Teun 

 

Will you confirm you sucessfully got your second search option from you reply using the IN operator working outside of Postman? HubSpot api returns: "...problem: operator IN requires values." when using the following filter & operator:

 

"propertyName""dealstage""operator""IN""values": [84643078464306] }
 
We are able to get it working in Postman and would like to know if their is a bug with the following node package:
 
@hubspot/api-client v6.0.1
 
api call:
const apiResponse = await hubspotClient.crm.deals.searchApi.doSearch(publicObjectSearchRequest);
0 Upvotes
tb1024
Participant

[Hubspot API] How do you use IN filter operator?

SOLVE

Teun,

It seems that your last example doesn't work for me, I am getting this error:

 

{"status":"error","message":"Invalid input JSON on line 9, column 17: Cannot construct instance of `com.hubspot.inbounddb.publicobject.core.v3.search.Filter`, problem: operator IN requires values","correlationId":"c0f97d27-fd9c-4e21-a476-ed9ee20a2000"}

 

 

This is what I have in Postman. Any input would highly be appreciated. Thank you.

tb1024_0-1644586988118.png

 

0 Upvotes
tb1024
Participant

[Hubspot API] How do you use IN filter operator?

SOLVE

Teun,

For future reference, it looks like you have a typo in your sample. It should be "values" (plural) instead of "value".  Also, it is looking for a string[]  (see picture).

tb1024_0-1644588012904.png

 

Teun
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

[Hubspot API] How do you use IN filter operator?

SOLVE

Thanks for the update!



Did my answer solve your issue? Help the community by marking it as the solution.
0 Upvotes
CSwart
Participant

[Hubspot API] How do you use IN filter operator?

SOLVE

Thanks for the helpful solution ideas I am going to try them out today!