Oct 20, 2021 5:09 AM
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.
Solved! Go to Solution.
Oct 20, 2021 1:37 PM
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)
Nov 30, 2022 4:32 AM
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"
]
}
Mar 31, 2022 11:01 AM
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?
Mar 31, 2022 10:52 AM
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?
Mar 22, 2022 2:50 PM
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' }]
}
Mar 31, 2022 11:31 AM
are you able to filter using any other values other than closedlost and closedwon such as custom stages?
Oct 20, 2021 1:37 PM
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)
Feb 14, 2022 7:17 PM
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:
Feb 11, 2022 8:44 AM - edited Feb 11, 2022 8:44 AM
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.
Feb 11, 2022 9:00 AM
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).
Feb 15, 2022 4:09 AM
Oct 21, 2021 6:00 AM
Thanks for the helpful solution ideas I am going to try them out today!