'Use OR filter for metrics in the Facebook Ads API
I'm trying to use an OR filter in the Facebook Ads API. I want to fetch all campaigns that has impressions > 0 OR spend > 0. According to the Facebook Ads API documentation you can use "Formula fields" to set arithmetic expressions as a field, so I figured that I could fetch campaigns with "impressions + cost" as a field.
With the below code I get the following error: "Filtering field 'impressions + spend' is not supported". Using only e.g. "impressions" works fine. I tried examples from the documentation like: "0.8 * cpc", but got the same error.
Do anybody know how Formula Fields in the Facebook API should be used?
$fields = [CampaignFields::OBJECTIVE, CampaignFields::ID, CampaignFields::STATUS, CampaignFields::NAME];
$params = [
'limit' => PHP_INT_MAX,
CampaignFields::EFFECTIVE_STATUS => [CampaignEffectiveStatusValues::ACTIVE],
'filtering' => [['field' => 'impressions + spend', 'operator' => InsightsOperators::GREATER_THAN, 'value' => 0]],
'date_preset' => InsightsResultDatePresetValues::YESTERDAY,];
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
