I’ve set up a custom field in HubSpot for companies called erp_identifier. We need to verify if any companies match a list of these identifiers by using the IN operator in the API. However, I encountered an issue where the query only works if every value in the list exists in the database. I expected the API to return partial matches and ignore the non-existent identifiers. Is the API designed to function this way?
In this sample, only one identifier actually exists in the companies table, yet the query returns no results. If I remove the non-existent identifiers and search with just the valid one, the API responds correctly.
Am I misunderstanding how the IN operator is supposed to work with partial matches in HubSpot’s API?
Based on my experience working with HubSpot’s API, the IN operator does indeed behave as you’ve described. It’s designed to return results only when all specified values in the list match existing records. This can be frustrating when you’re trying to query for partial matches.
A workaround I’ve used is to split the query into multiple filter groups, each containing a single value. This approach allows for partial matches. Here’s how you could modify your API call:
I’ve encountered this exact issue with HubSpot’s API before. It’s a bit counterintuitive, but the IN operator does require all values to exist for a match. One approach that’s worked well for me is using the CONTAINS_TOKEN operator instead. It’s more flexible and allows for partial matches. Your query might look something like this:
This method searches for any of the tokens within the erp_identifier field, effectively giving you the partial match functionality you’re after. It’s been a reliable workaround in my projects when dealing with similar scenarios.