APIs & Integrations

DBiler
Participant

how to set api filter for "multiple checkboxes" field type?

SOLVE

hi,

 

I have this custom property for Contacts called "mh_instance" (internal value)

 Screen Shot 2022-03-18 at 8.14.55 AM.png

 

Currently, this is how i do it

 

 

 

$client = \HubSpot\Factory::createWithApiKey('MY_API_KEY'); 
$searchRequest = new \HubSpot\Client\Crm\Contacts\Model\PublicObjectSearchRequest(); 
$filters = []; 
$conditions = [ 'email' => 'test@example.com', 'mh_instance' => 'AU' ]; 
$field_operators = [ 'email' => 'EQ', 'mh_instance' => 'IN' ]; 
$fields = ['email']; 

foreach($conditions as $property_name => $property_value){ 
    $curFilter = new \HubSpot\Client\Crm\Contacts\Model\Filter(); 
    $operator = $field_operator[$property_name]; 
    $curFilter->setOperator($operator)->setPropertyName($property_name)->setValue($property_value); 
    $filters[] = $curFilter;
 } 
 
 $filterGroup = new \HubSpot\Client\Crm\Contacts\Model\FilterGroup(); 
 $filterGroup->setFilters($filters); 
 $searchRequest->setFilterGroups([$filterGroup]); 
 $searchRequest->setProperties($fields); 
 $searchRequest->setLimit(1); 
 
 try { 
     $apiResponse = $client->crm()->contacts()->searchApi()->doSearch($searchRequest); 

     if($apiResponse['total'] >= 1){ 
         $tmp = $apiResponse['results'][0]['properties']; 
         return [ 
            'id' => $tmp['hs_object_id'], 'date_added' => $tmp['createdate'], 'date_modified' => $tmp['lastmodifieddate'] 
        ];
    } 
    else 
        return false; 
} 
 catch (ApiException $e) { return false; }

 

 

 

request body

{
  "filterGroups": [
    {
      "filters": [
        {
          "value": "AU",
          "propertyName": "mh_instance",
          "operator": "IN"
        },
        {
          "value": "test@example.com",
          "propertyName": "email",
          "operator": "EQ"
        }
      ]
    }
  ],
  "properties": [
    "email",
    "mh_instance"
  ],
  "limit": 100
}

 

 

but im getting the following result 

 

 

 

{
  "status": "error",
  "message": "Invalid input JSON on line 1, column 88: Cannot construct instance of `com.hubspot.inbounddb.publicobject.core.v3.search.Filter`, problem: operator IN requires values",
  "correlationId": "2c85d210-c5f2-4849-9c75-291e44851a45"
}

 

 

 

 

0 Upvotes
1 Accepted solution
dennisedson
Solution
HubSpot Product Team
HubSpot Product Team

how to set api filter for "multiple checkboxes" field type?

SOLVE

@DBiler 

Are you just wanting to check if there is a value in the property or are you wanting that specific value?

If first: HAS_PROPERTY

If second: EQ

 

View solution in original post

0 Upvotes
1 Reply 1
dennisedson
Solution
HubSpot Product Team
HubSpot Product Team

how to set api filter for "multiple checkboxes" field type?

SOLVE

@DBiler 

Are you just wanting to check if there is a value in the property or are you wanting that specific value?

If first: HAS_PROPERTY

If second: EQ

 

0 Upvotes