Deal Search API in Custom_Code of Workflow Step. Filter Multiple Checkbox Field

SOLVE
soccery387
Member

I have a Custom_Code Step where I'm searching deals on a field that is a multi-select.  If I search for a specific value it equals, it works fine, but the minute I change it to see if it has one of the items checked, it does not

 

WORKS

const PublicObjectSearchRequest = {
    "properties": ["dealname","project_type" ],
    "limit": 100,
    "sorts": [
      {
        "propertyName": "project_type",
        "direction": "DESCENDING"
      }
    ],
    "filterGroups":[
      {
        "filters":[
          {
            "propertyName": "project_type",
            "operator": "EQ",
            "value": "AB"
          }
        ]
      }
    ]
  }
const apiResponse = await hubspotClient.crm.deals.searchApi.doSearch(PublicObjectSearchRequest);


DOES NOT WORK

const PublicObjectSearchRequest = {
    "properties": ["dealname","project_type" ],
    "limit": 100,
    "sorts": [
      {
        "propertyName": "project_type",
        "direction": "DESCENDING"
      }
    ],
    "filterGroups":[
      {
        "filters":[
          {
            "propertyName": "project_type",
            "operator": "IN",
            "values": ["CD","AB"]
          }
        ]
      }
    ]
  }
const apiResponse = await hubspotClient.crm.deals.searchApi.doSearch(PublicObjectSearchRequest);

 


Can someone assist with what's being missed here?

0 Upvotes
1 Accepted solution

Accepted Solutions
webdew
Solution
Guide | Diamond Partner

Hi @soccery387 ,

please use this code :
var options = { method: 'POST',
url: 'https://api.hubapi.com/crm/v3/objects/deals/search',
qs: { hapikey: '' },
headers:
{
'Content-Type': 'application/json' },
body: {
"filterGroups":[
{
"filters":[
{
"propertyName": "pipeline",
"operator": "EQ",
"value": "agent_sales"
},
{
"propertyName": "dealstage",
"operator": "EQ",
"value": "booking_stage"
},
{
"propertyName": "associations.contact",
"operator": "EQ",
"value": event.object.objectId
}
]
}
]
},
json: true };

request(options, function (error, response, body) {


Hope this helps!
If we were able to answer your query, kindly help the community by marking it as a solution.
Thanks and Regard.

View solution in original post

0 Upvotes
3 Replies 3
Teun
Key Advisor | Diamond Partner

Hi @soccery387 ,

I might be completely wrong here, but is "IN" a valid operator for the Search API?
You could pass multiple filterGroups with the "EQ" operator instead. When multiple filterGroups are included in the request body, they'll be combined using a logical OR operator.



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

@Teun thanks for your reply.  I can use the "IN" operator with Deal Search when I do this in Postman.  I just cannot get it to work within a Workflow Custom_Code Step.  I understand I could use the EQ and stack multiple requests, but am trying to keep the requests and code clean

0 Upvotes
webdew
Solution
Guide | Diamond Partner

Hi @soccery387 ,

please use this code :
var options = { method: 'POST',
url: 'https://api.hubapi.com/crm/v3/objects/deals/search',
qs: { hapikey: '' },
headers:
{
'Content-Type': 'application/json' },
body: {
"filterGroups":[
{
"filters":[
{
"propertyName": "pipeline",
"operator": "EQ",
"value": "agent_sales"
},
{
"propertyName": "dealstage",
"operator": "EQ",
"value": "booking_stage"
},
{
"propertyName": "associations.contact",
"operator": "EQ",
"value": event.object.objectId
}
]
}
]
},
json: true };

request(options, function (error, response, body) {


Hope this helps!
If we were able to answer your query, kindly help the community by marking it as a solution.
Thanks and Regard.

View solution in original post

0 Upvotes