how to filter with "OR"
lsmith77 opened this issue · comments
I am trying to find users based on their email. Now it seems like email
or hs_additional_emails
can contain the given email.
it seems however that the SDK defaults to AND
filters and I don't see how to do an OR
filter
$filter = new HubSpotFilter();
$filter
->setOperator('EQ')
->setPropertyName('email')
->setValue($user->email);
$filterAdditional = new HubSpotFilter();
$filterAdditional
->setOperator('EQ')
->setPropertyName('hs_additional_emails')
->setValue($user->email);
$filterGroup = new HubSpotFilterGroup();
$filterGroup->setFilters([$filter, $filterAdditional]);
Hi @lsmith77
When multiple filters
are present within a filterGroup
, they'll be combined using a logical AND
operator.
When multiple filterGroups
are included in the request body, they'll be combined using a logical OR
operator.
Workable example:
$hubspot = Factory::createWithAccessToken('*');
$theFirstFilter = new Filter([
'value' => 'thefirst@example.com',
'property_name' => 'email',
'operator' => Filter::OPERATOR_EQ
]);
$theFirstFilterGroup = new FilterGroup(['filters' => [$theFirstFilter]]);
$theSecondFilter = new Filter([
'value' => 'workthesecond@example.com',
'property_name' => 'work_email',
'operator' => Filter::OPERATOR_EQ
]);
$theSecondFilterGroup = new FilterGroup(['filters' => [$theSecondFilter]]);
$request = new PublicObjectSearchRequest(['filter_groups' => [$theFirstFilterGroup, $theSecondFilterGroup]]);
$hubspot->crm()->contacts()->searchApi()->doSearch($request);