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

**URL:** <https://community.hubspot.com/t/hubspot-api-how-do-you-use-in-filter-operator/45613>\
**Category:** APIs & Integrations\
**Tags:** python\
**Created:** [October 20, 2021, 9:09am UTC](https://community.hubspot.com/t/hubspot-api-how-do-you-use-in-filter-operator/45613 "2021-10-20T09:09:40Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![CSwart](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/cswart/32/60590_2.png) [@CSwart](https://community.hubspot.com/u/CSwart)\
**Post date:** [October 20, 2021, 9:09am UTC](https://community.hubspot.com/t/hubspot-api-how-do-you-use-in-filter-operator/45613/1 "2021-10-20T09:09:40Z")

</div>

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:

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

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

```auto
{'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.

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [October 20, 2021, 5:37pm UTC](https://community.hubspot.com/t/hubspot-api-how-do-you-use-in-filter-operator/45613/2 "2021-10-20T17:37:56Z")

</div>

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

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

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

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

```

---

<div class="post-metadata">

**Author:** ![CSwart](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/cswart/32/60590_2.png) [@CSwart](https://community.hubspot.com/u/CSwart)\
**Post date:** [October 21, 2021, 10:00am UTC](https://community.hubspot.com/t/hubspot-api-how-do-you-use-in-filter-operator/45613/3 "2021-10-21T10:00:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tb1024](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tb1024/32/29572_2.png) [@tb1024](https://community.hubspot.com/u/tb1024)\
**Post date:** [February 11, 2022, 1:44pm UTC](https://community.hubspot.com/t/hubspot-api-how-do-you-use-in-filter-operator/45613/4 "2022-02-11T13:44:00Z")

</div>

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](https://d2qpr2jzcazej7.cloudfront.net/original/3X/d/e/de6c2451e48488a5b25cb980dc8a9b73638f1c0f.png)

---

<div class="post-metadata">

**Author:** ![tb1024](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tb1024/32/29572_2.png) [@tb1024](https://community.hubspot.com/u/tb1024)\
**Post date:** [February 11, 2022, 2:00pm UTC](https://community.hubspot.com/t/hubspot-api-how-do-you-use-in-filter-operator/45613/5 "2022-02-11T14:00:26Z")

</div>

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](https://d2qpr2jzcazej7.cloudfront.net/original/3X/f/1/f10cb2ade5a7390b62385fde7d6fb4dd6050cac9.png)

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [February 15, 2022, 9:09am UTC](https://community.hubspot.com/t/hubspot-api-how-do-you-use-in-filter-operator/45613/6 "2022-02-15T09:09:46Z")

</div>

Thanks for the update!

---

<div class="post-metadata">

**Author:** ![mooney](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@mooney](https://community.hubspot.com/u/mooney)\
**Post date:** [February 15, 2022, 12:17am UTC](https://community.hubspot.com/t/hubspot-api-how-do-you-use-in-filter-operator/45613/7 "2022-02-15T00:17:58Z")

</div>

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”: [8464307, 8464306] }

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);

---

<div class="post-metadata">

**Author:** ![Petercopter](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@Petercopter](https://community.hubspot.com/u/Petercopter)\
**Post date:** [March 22, 2022, 6:50pm UTC](https://community.hubspot.com/t/hubspot-api-how-do-you-use-in-filter-operator/45613/8 "2022-03-22T18:50:45Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![mooney](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@mooney](https://community.hubspot.com/u/mooney)\
**Post date:** [March 31, 2022, 3:31pm UTC](https://community.hubspot.com/t/hubspot-api-how-do-you-use-in-filter-operator/45613/9 "2022-03-31T15:31:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BSeslija](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/bseslija/32/53612_2.png) [@BSeslija](https://community.hubspot.com/u/BSeslija)\
**Post date:** [March 31, 2022, 2:52pm UTC](https://community.hubspot.com/t/hubspot-api-how-do-you-use-in-filter-operator/45613/10 "2022-03-31T14:52:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![BSeslija](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/bseslija/32/53612_2.png) [@BSeslija](https://community.hubspot.com/u/BSeslija)\
**Post date:** [March 31, 2022, 3:01pm UTC](https://community.hubspot.com/t/hubspot-api-how-do-you-use-in-filter-operator/45613/11 "2022-03-31T15:01:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![SNowak6](https://avatars.discourse-cdn.com/v4/letter/s/a88e57/32.png) [@SNowak6](https://community.hubspot.com/u/SNowak6)\
**Post date:** [November 30, 2022, 9:32am UTC](https://community.hubspot.com/t/hubspot-api-how-do-you-use-in-filter-operator/45613/12 "2022-11-30T09:32:31Z")

</div>

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?
